Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Goal {
balance: number
targetDate: Date
created: Date
icon?: string
accountId: string
transactionIds: string[]
tagIds: string[]
Expand Down
37 changes: 36 additions & 1 deletion src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { selectGoalsMap, updateGoal as updateGoalRedux } from '../../../store/go
import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import { Theme } from '../../components/Theme'

import { BaseEmoji } from 'emoji-mart'
import EmojiPicker from '../../components/EmojiPicker'
import GoalIcon from './GoalIcon'
import AddIconButton from './AddIconButton'
type Props = { goal: Goal }
export function GoalManager(props: Props) {
const dispatch = useAppDispatch()
Expand All @@ -21,6 +24,8 @@ export function GoalManager(props: Props) {
const [name, setName] = useState<string | null>(null)
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)
const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState(false)
const [icon, setIcon] = useState<string | null>(props.goal.icon ?? null)

useEffect(() => {
setName(props.goal.name)
Expand Down Expand Up @@ -74,9 +79,39 @@ export function GoalManager(props: Props) {
updateGoalApi(props.goal.id, updatedGoal)
}
}
const pickEmojiOnClick = () => (emoji: BaseEmoji, event: React.MouseEvent) => {
setIcon(emoji.native)
setIsEmojiPickerOpen(false)

const updatedGoal: Goal = {
...props.goal,
icon: emoji.native ?? props.goal.icon,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
}

dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}

return (
<GoalManagerContainer>
{icon ? (
<GoalIcon
icon={icon}
onClick={() => setIsEmojiPickerOpen(!isEmojiPickerOpen)}
/>
) : (
<AddIconButton
hasIcon={false}
onClick={() => setIsEmojiPickerOpen(true)}
/>
)}

{isEmojiPickerOpen && (
<EmojiPicker onClick={pickEmojiOnClick()} />
)}
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

<Group>
Expand Down
2 changes: 2 additions & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import GoalIcon from '../../../features/goalmanager/GoalIcon'
import styled from 'styled-components'
import { selectGoalsMap } from '../../../../store/goalsSlice'
import { useAppDispatch, useAppSelector } from '../../../../store/hooks'
Expand Down Expand Up @@ -27,6 +28,7 @@ export default function GoalCard(props: Props) {

return (
<Container key={goal.id} onClick={onClick}>
<GoalIcon icon={goal.icon ?? '🎯'} onClick={() => {}} />
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
Expand Down