From 54f4da70d8c9fbc5dad96b24338d806b02653d87 Mon Sep 17 00:00:00 2001 From: Shivam3319 Date: Sat, 20 Jun 2026 12:44:03 +0530 Subject: [PATCH] Added goal icon and emoji picker support --- src/api/types.ts | 1 + src/ui/features/goalmanager/GoalManager.tsx | 46 +++++++++++++++++++-- src/ui/pages/Main/goals/GoalCard.tsx | 16 ++++--- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index f75edad..5beff48 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -20,6 +20,7 @@ export interface Application { export interface Goal { id: string name: string + icon?: string targetAmount: number balance: number targetDate: Date diff --git a/src/ui/features/goalmanager/GoalManager.tsx b/src/ui/features/goalmanager/GoalManager.tsx index 0779dda..5bc278d 100644 --- a/src/ui/features/goalmanager/GoalManager.tsx +++ b/src/ui/features/goalmanager/GoalManager.tsx @@ -11,6 +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 EmojiPicker from '../../components/EmojiPicker' +import { BaseEmoji } from 'emoji-mart' +import AddIconButton from './AddIconButton' +import GoalIcon from './GoalIcon' type Props = { goal: Goal } export function GoalManager(props: Props) { @@ -21,16 +25,20 @@ export function GoalManager(props: Props) { const [name, setName] = useState(null) const [targetDate, setTargetDate] = useState(null) const [targetAmount, setTargetAmount] = useState(null) + const [icon, setIcon] = useState(null) + const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState(false) useEffect(() => { - setName(props.goal.name) - setTargetDate(props.goal.targetDate) - setTargetAmount(props.goal.targetAmount) - }, [ + setName(props.goal.name) + setTargetDate(props.goal.targetDate) + setTargetAmount(props.goal.targetAmount) + setIcon(props.goal.icon ?? null) +}, [ props.goal.id, props.goal.name, props.goal.targetDate, props.goal.targetAmount, + props.goal.icon, ]) useEffect(() => { @@ -74,10 +82,40 @@ export function GoalManager(props: Props) { updateGoalApi(props.goal.id, updatedGoal) } } +const onEmojiClick = (emoji: BaseEmoji) => { + setIcon(emoji.native) + + const updatedGoal: Goal = { + ...props.goal, + icon: emoji.native, + name: name ?? props.goal.name, + targetDate: targetDate ?? props.goal.targetDate, + targetAmount: targetAmount ?? props.goal.targetAmount, + } + + dispatch(updateGoalRedux(updatedGoal)) + updateGoalApi(props.goal.id, updatedGoal) + setIsEmojiPickerOpen(false) +} return ( + {icon ? ( + setIsEmojiPickerOpen(!isEmojiPickerOpen)} + /> +) : ( + setIsEmojiPickerOpen(!isEmojiPickerOpen)} + /> +)} + +{isEmojiPickerOpen && ( + +)} diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx index e8f6d0a..4ced872 100644 --- a/src/ui/pages/Main/goals/GoalCard.tsx +++ b/src/ui/pages/Main/goals/GoalCard.tsx @@ -26,11 +26,13 @@ export default function GoalCard(props: Props) { const asLocaleDateString = (date: Date) => new Date(date).toLocaleDateString() return ( - - ${goal.targetAmount} - {asLocaleDateString(goal.targetDate)} - - ) + + {goal.icon && {goal.icon}} + + ${goal.targetAmount} + {asLocaleDateString(goal.targetDate)} + +) } const Container = styled(Card)` @@ -49,6 +51,10 @@ const Container = styled(Card)` const TargetAmount = styled.h2` font-size: 2rem; ` +const GoalIcon = styled.div` + font-size: 3rem; + margin-top: 1rem; +`; const TargetDate = styled.h4` color: rgba(174, 174, 174, 1);