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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
97 changes: 68 additions & 29 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Picker } from 'emoji-mart'
import 'emoji-mart/css/emoji-mart.css'
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
Expand All @@ -21,64 +23,101 @@ 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>(props.goal.icon ?? '')
const [pickerOpen, setPickerOpen] = useState(false)
useEffect(() => {
setName(props.goal.name)
setTargetDate(props.goal.targetDate)
setTargetAmount(props.goal.targetAmount)
setIcon(props.goal.icon ?? '')
}, [
props.goal.id,
props.goal.name,
props.goal.targetDate,
props.goal.targetAmount,
[
props.goal.id,
props.goal.name,
props.goal.targetDate,
props.goal.targetAmount,
props.goal.icon,
]
])

useEffect(() => {
setName(goal.name)
}, [goal.name])
setName(goal.name)
setIcon(goal.icon ?? '')
}, [goal.name, goal.icon])

const updateNameOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextName = event.target.value
setName(nextName)
const updatedGoal: Goal = {
...props.goal,
name: nextName,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
const nextName = event.target.value
setName(nextName)

const updatedGoal: Goal = {
...props.goal,
name: nextName,
icon: icon,
}

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

const updateTargetAmountOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextTargetAmount = parseFloat(event.target.value)
setTargetAmount(nextTargetAmount)

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

dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
const pickEmojiOnClick = (emoji: any) => {
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
icon: emoji.native,
}

setIcon(emoji.native)
setPickerOpen(false)

dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
const pickDateOnChange = (date: MaterialUiPickersDate) => {
if (date != null) {
setTargetDate(date)
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
targetDate: date ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
if (date != null) {
setTargetDate(date)

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

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

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

<button onClick={() => setPickerOpen(!pickerOpen)}>
{icon || "😀"}
</button>

{pickerOpen && (
<Picker onSelect={pickEmojiOnClick} />
)}

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
Expand Down
17 changes: 12 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,14 @@ 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}>
<Icon>{goal.icon || "🎯"}</Icon>

<TargetAmount>${goal.targetAmount}</TargetAmount>

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

const Container = styled(Card)`
Expand All @@ -46,6 +49,10 @@ const Container = styled(Card)`

align-items: center;
`
const Icon = styled.div`
font-size: 3rem;
margin-top: 1rem;
`
const TargetAmount = styled.h2`
font-size: 2rem;
`
Expand Down