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
17 changes: 9 additions & 8 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@material-ui/core": "^4.12.4",
"@material-ui/pickers": "^3.3.10",
"@reduxjs/toolkit": "^1.5.1",
"@types/emoji-mart": "^3.0.5",
"@types/node": "^17.0.41",
"@types/react": "^16.9.0",
"@types/react-redux": "^7.1.7",
Expand Down Expand Up @@ -55,8 +54,8 @@
]
},
"devDependencies": {
"@types/emoji-mart": "^3.0.9",
"@types/emoji-mart": "^3.0.14",
"@types/react-dom": "^18.0.5",
"@types/styled-components": "^5.1.25"
}
}
}
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 | null
}

export interface Tag {
Expand Down
3 changes: 3 additions & 0 deletions src/ui/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import { Theme } from './Theme'
export const Card = styled.div`
background-color: ${({ theme }: { theme: Theme }) => theme.cardBackground};
box-shadow: ${({ theme }: { theme: Theme }) => theme.boxShadow};



`
45 changes: 39 additions & 6 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ 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 GoalIcon from './GoalIcon'
import { Picker } from 'emoji-mart'
import 'emoji-mart/css/emoji-mart.css'

type Props = { goal: Goal }
export function GoalManager(props: Props) {
Expand All @@ -21,16 +24,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 [showPicker, setShowPicker] = 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,10 +82,35 @@ export function GoalManager(props: Props) {
}
}

const onEmojiSelect = (emoji: any) => {
const nextIcon = emoji.native
setIcon(nextIcon)
setShowPicker(false)
const updatedGoal: Goal = {
...props.goal,
icon: nextIcon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}

const onGoalIconClick = (e: React.MouseEvent) => {
e.stopPropagation()
setShowPicker(!showPicker)
}

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

<GoalIcon icon={icon} onClick={onGoalIconClick} />

{showPicker && (
<EmojiPickerContainer>
<Picker onSelect={onEmojiSelect} />
</EmojiPickerContainer>
)}

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
Expand Down Expand Up @@ -111,9 +143,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 @@ -131,7 +160,6 @@ const GoalManagerContainer = styled.div`
width: 100%;
position: relative;
`

const Group = styled.div`
display: flex;
flex-direction: row;
Expand All @@ -148,7 +176,6 @@ const NameInput = styled.input`
font-weight: bold;
color: ${({ theme }: { theme: Theme }) => theme.text};
`

const FieldName = styled.h1`
font-size: 1.8rem;
margin-left: 1rem;
Expand Down Expand Up @@ -178,7 +205,13 @@ const StringInput = styled.input`
font-weight: bold;
color: ${({ theme }: { theme: Theme }) => theme.text};
`

const Value = styled.div`
margin-left: 2rem;
`
const EmojiPickerContainer = styled.div`
position: absolute;
top: 12rem;
left: 0;
z-index: 100;
`

9 changes: 5 additions & 4 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Props = { id: string }

export default function GoalCard(props: Props) {
const dispatch = useAppDispatch()

const goal = useAppSelector(selectGoalsMap)[props.id]

const onClick = (event: React.MouseEvent) => {
Expand All @@ -27,6 +26,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 @@ -43,14 +43,15 @@ const Container = styled(Card)`
margin-left: 2rem;
margin-right: 2rem;
border-radius: 2rem;

align-items: center;
`
const Icon = styled.h1`
font-size: 3rem;
`
const TargetAmount = styled.h2`
font-size: 2rem;
`

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