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.

3 changes: 2 additions & 1 deletion src/api/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import { user } from '../data/user'
import { Goal, Transaction, User } from './types'

export const API_ROOT = 'https://fencer-commbank.azurewebsites.net'
export const API_ROOT = 'http://localhost:11366'

export async function getUser(): Promise<User | null> {
try {
Expand Down Expand Up @@ -51,3 +51,4 @@ export async function updateGoal(goalId: string, updatedGoal: Goal): Promise<boo
return false
}
}

5 changes: 3 additions & 2 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export interface Goal {
created: Date
accountId: string
transactionIds: string[]
tagIds: string[]
tagIds: string[],
icon?: string
}

export interface Tag {
Expand All @@ -41,7 +42,7 @@ export interface Transaction {
dateTime: Date
goalId?: string
description: string
tagIds: string[]
tagIds: string[]
}

export interface User {
Expand Down
53 changes: 52 additions & 1 deletion src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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'

type Props = { goal: Goal }
export function GoalManager(props: Props) {
Expand Down Expand Up @@ -74,11 +76,38 @@ export function GoalManager(props: Props) {
updateGoalApi(props.goal.id, updatedGoal)
}
}
const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)
const [icon, setIcon] = useState<string | null>(props.goal.icon ?? null)

const pickEmojiOnClick = (emoji: BaseEmoji, event: React.MouseEvent) => {
event.stopPropagation()

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

setIcon(emoji.native)
setEmojiPickerIsOpen(false)

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


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

<EmojiPickerContainer
isOpen={emojiPickerIsOpen}
hasIcon={icon != null}
onClick={(event) => event.stopPropagation()}
>
<EmojiPicker onClick={pickEmojiOnClick} />
</EmojiPickerContainer>
<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
Expand Down Expand Up @@ -106,6 +135,18 @@ export function GoalManager(props: Props) {
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>
<button
type="button"
onClick={() => setEmojiPickerIsOpen(!emojiPickerIsOpen)}
style={{
fontSize: '2.5rem',
background: 'transparent',
border: 'none',
cursor: 'pointer'
}}
>
{icon ?? '➕'}
</button>
</GoalManagerContainer>
)
}
Expand Down Expand Up @@ -182,3 +223,13 @@ const StringInput = styled.input`
const Value = styled.div`
margin-left: 2rem;
`

const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${(props) => (props.isOpen ? 'flex' : 'none')};
position: absolute;
top: ${(props) => (props.hasIcon ? '10rem' : '2rem')};
left: 0;
z-index: 10;
`


6 changes: 6 additions & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function GoalCard(props: Props) {

return (
<Container key={goal.id} onClick={onClick}>
<Icon>{goal.icon}</Icon>
{goal.name}
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
Expand Down Expand Up @@ -54,3 +56,7 @@ const TargetDate = styled.h4`
color: rgba(174, 174, 174, 1);
font-size: 1rem;
`
const Icon = styled.h1`
font-size: 5.5rem;
margin-top: 1rem;
`