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
46 changes: 42 additions & 4 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -21,16 +25,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)
}, [
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 @@ -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 (
<GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />
{icon ? (
<GoalIcon
icon={icon}
onClick={() => setIsEmojiPickerOpen(!isEmojiPickerOpen)}
/>
) : (
<AddIconButton
hasIcon={false}
onClick={() => setIsEmojiPickerOpen(!isEmojiPickerOpen)}
/>
)}

{isEmojiPickerOpen && (
<EmojiPicker onClick={onEmojiClick} />
)}

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
Expand Down
16 changes: 11 additions & 5 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export default function GoalCard(props: Props) {
const asLocaleDateString = (date: Date) => new Date(date).toLocaleDateString()

return (
<Container key={goal.id} onClick={onClick}>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
)
<Container key={goal.id} onClick={onClick}>
{goal.icon && <GoalIcon>{goal.icon}</GoalIcon>}

<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
)
}

const Container = styled(Card)`
Expand All @@ -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);
Expand Down