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 @@ -20,6 +20,7 @@ export interface Application {
export interface Goal {
id: string
name: string
icon?: string
targetAmount: number
balance: number
targetDate: Date
Expand Down
41 changes: 40 additions & 1 deletion src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ 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 AddIconButton from './AddIconButton'
import GoalIcon from './GoalIcon'
import EmojiPicker from '../../components/EmojiPicker'
import { BaseEmoji } from 'emoji-mart'


type Props = { goal: Goal }
export function GoalManager(props: Props) {
Expand All @@ -21,16 +26,20 @@ 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 [icon, setIcon] = useState<string | null>(null)
const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState(false)

useEffect(() => {
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(() => {
Expand Down Expand Up @@ -75,10 +84,40 @@ export function GoalManager(props: Props) {
}
}

const selectEmoji = (emoji: BaseEmoji) => {
setIcon(emoji.native)
setIsEmojiPickerOpen(false)

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

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

return (
<GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

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

{isEmojiPickerOpen && (
<EmojiPicker onClick={selectEmoji} />
)}
<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
Expand Down
1 change: 1 addition & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function GoalCard(props: Props) {

return (
<Container key={goal.id} onClick={onClick}>
{goal.icon && <div style={{ fontSize: '3rem' }}>{goal.icon}</div>}
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
Expand Down