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
Empty file added cd
Empty file.
Empty file added cmd
Empty file.
Empty file added dir
Empty file.
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Goal {
accountId: string
transactionIds: string[]
tagIds: string[]
icon?: string
}

export interface Tag {
Expand Down
59 changes: 55 additions & 4 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
import { BaseEmoji } from 'emoji-mart'
import 'date-fns'
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
Expand All @@ -10,7 +11,10 @@ import { Goal } from '../../../api/types'
import { selectGoalsMap, updateGoal as updateGoalRedux } from '../../../store/goalsSlice'
import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import EmojiPicker from '../../components/EmojiPicker'
import { Theme } from '../../components/Theme'
import GoalIcon from './GoalIcon'
import AddIconButton from './AddIconButton'

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 [showEmojiPicker, setShowEmojiPicker] = useState<boolean>(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,8 +83,42 @@ export function GoalManager(props: Props) {
}
}

const toggleEmojiPicker = (e: React.MouseEvent) => {
e.stopPropagation()
setShowEmojiPicker(!showEmojiPicker)
}

const onEmojiClick = (emoji: BaseEmoji, event: React.MouseEvent) => {
event.stopPropagation()
const nextIcon = emoji.native
setIcon(nextIcon)
setShowEmojiPicker(false)
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
icon: nextIcon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}

return (
<GoalManagerContainer>
<IconSection>
{icon ? (
<GoalIcon icon={icon} onClick={toggleEmojiPicker} />
) : (
<AddIconButton hasIcon={false} onClick={toggleEmojiPicker} />
)}
{showEmojiPicker && (
<EmojiPickerContainer>
<EmojiPicker onClick={onEmojiClick} />
</EmojiPickerContainer>
)}
</IconSection>

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

<Group>
Expand Down Expand Up @@ -111,9 +153,6 @@ export function GoalManager(props: Props) {
}

type FieldProps = { name: string; icon: IconDefinition }
type AddIconButtonContainerProps = { shouldShow: boolean }
type GoalIconContainerProps = { shouldShow: boolean }
type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean }

const Field = (props: FieldProps) => (
<FieldContainer>
Expand All @@ -132,6 +171,18 @@ const GoalManagerContainer = styled.div`
position: relative;
`

const IconSection = styled.div`
position: relative;
margin-bottom: 1rem;
`

const EmojiPickerContainer = styled.div`
position: absolute;
top: 100%;
left: 0;
z-index: 100;
`

const Group = styled.div`
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -181,4 +232,4 @@ const StringInput = styled.input`

const Value = styled.div`
margin-left: 2rem;
`
`
9 changes: 8 additions & 1 deletion 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 && <Icon>{goal.icon}</Icon>}
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
Expand All @@ -46,11 +47,17 @@ const Container = styled(Card)`

align-items: center;
`

const Icon = styled.span`
font-size: 3rem;
margin-bottom: 0.5rem;
`

const TargetAmount = styled.h2`
font-size: 2rem;
`

const TargetDate = styled.h4`
color: rgba(174, 174, 174, 1);
font-size: 1rem;
`
`