diff --git a/src/api/types.ts b/src/api/types.ts index f75edad..9214169 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -24,6 +24,7 @@ export interface Goal { balance: number targetDate: Date created: Date + icon?: string accountId: string transactionIds: string[] tagIds: string[] diff --git a/src/ui/features/goalmanager/GoalManager.tsx b/src/ui/features/goalmanager/GoalManager.tsx index 0779dda..186e600 100644 --- a/src/ui/features/goalmanager/GoalManager.tsx +++ b/src/ui/features/goalmanager/GoalManager.tsx @@ -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() @@ -21,6 +24,8 @@ export function GoalManager(props: Props) { const [name, setName] = useState(null) const [targetDate, setTargetDate] = useState(null) const [targetAmount, setTargetAmount] = useState(null) + const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState(false) + const [icon, setIcon] = useState(props.goal.icon ?? null) useEffect(() => { setName(props.goal.name) @@ -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 ( + {icon ? ( + setIsEmojiPickerOpen(!isEmojiPickerOpen)} + /> + ) : ( + setIsEmojiPickerOpen(true)} + /> + )} + + {isEmojiPickerOpen && ( + + )} diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx index e8f6d0a..4f44e19 100644 --- a/src/ui/pages/Main/goals/GoalCard.tsx +++ b/src/ui/pages/Main/goals/GoalCard.tsx @@ -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' @@ -27,6 +28,7 @@ export default function GoalCard(props: Props) { return ( + {}} /> ${goal.targetAmount} {asLocaleDateString(goal.targetDate)}