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 @@ -27,6 +27,7 @@ export interface Goal {
accountId: string
transactionIds: string[]
tagIds: string[]
icon: string | null
}

export interface Tag {
Expand Down
11 changes: 9 additions & 2 deletions src/store/goalsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ export const goalsSlice = createSlice({
name: 'goal',
initialState,
reducers: {
createGoal: (state, action: PayloadAction<Goal>) => {
/*createGoal: (state, action: PayloadAction<Goal>) => {
state.map[action.payload.id] = action.payload
state.list.push(action.payload.id)
},
},*/
createGoal: (state, action: PayloadAction<Goal>) => {
if (!state.map[action.payload.id]) {
state.map[action.payload.id] = action.payload
state.list.push(action.payload.id)
}
},


updateGoal: (state, action: PayloadAction<Goal>) => {
state.map[action.payload.id] = action.payload
Expand Down
62 changes: 59 additions & 3 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 EmojiPicker from '../../components/EmojiPicker'
import AddIconButton from './AddIconButton'
import GoalIcon from './GoalIcon'
type Props = { goal: Goal }
export function GoalManager(props: Props) {
const dispatch = useAppDispatch()
Expand All @@ -21,6 +23,8 @@ 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 [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)

useEffect(() => {
setName(props.goal.name)
Expand All @@ -32,6 +36,9 @@ export function GoalManager(props: Props) {
props.goal.targetDate,
props.goal.targetAmount,
])
useEffect(() => {
setIcon(props.goal.icon)
}, [props.goal.id, props.goal.icon])

useEffect(() => {
setName(goal.name)
Expand Down Expand Up @@ -74,11 +81,51 @@ export function GoalManager(props: Props) {
updateGoalApi(props.goal.id, updatedGoal)
}
}
const hasIcon = () => icon != null

const addIconOnClick = (event: React.MouseEvent) => {
event.stopPropagation()
setEmojiPickerIsOpen(true)
}

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

setIcon(emoji.native)
setEmojiPickerIsOpen(false)

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

dispatch(updateGoalRedux(updatedGoal))

// TODO(TASK-3) Update database
}
return (
<GoalManagerContainer>
<EmojiPickerContainer
isOpen={emojiPickerIsOpen}
hasIcon={hasIcon()}
onClick={(event) => event.stopPropagation()}
>
<EmojiPicker onClick={pickEmojiOnClick} />
</EmojiPickerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

<AddIconButton
hasIcon={hasIcon()}
onClick={addIconOnClick}
/>
<GoalIconContainer shouldShow={hasIcon()}>
<GoalIcon
icon={icon}
onClick={addIconOnClick}
/>
</GoalIconContainer>
<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
Expand Down Expand Up @@ -107,11 +154,11 @@ export function GoalManager(props: Props) {
</Value>
</Group>
</GoalManagerContainer>

)
}

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

Expand Down Expand Up @@ -182,3 +229,12 @@ const StringInput = styled.input`
const Value = styled.div`
margin-left: 2rem;
`
const GoalIconContainer = styled.div<GoalIconContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
`
const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${(props) => (props.isOpen ? 'flex' : 'none')};
position: absolute;
top: ${(props) => (props.hasIcon ? '10rem' : '2rem')};
left: 0;
`
13 changes: 9 additions & 4 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export default function GoalCard(props: Props) {
}

const asLocaleDateString = (date: Date) => new Date(date).toLocaleDateString()

//console.log("GoalCard", props.id, goal)
return (
<Container key={goal.id} onClick={onClick}>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
<Icon>{goal.icon}</Icon>

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

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

align-items: center;
`
const Icon = styled.h1`
font-size: 5.5rem;
`
const TargetAmount = styled.h2`
font-size: 2rem;
`
Expand Down
5 changes: 4 additions & 1 deletion src/ui/pages/Main/goals/GoalsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import GoalsContent from './GoalsContent'
export default function GoalsSection() {
const dispatch = useAppDispatch()
const goalIds = useAppSelector(selectGoalsList)

//console.log("Goal IDs count:", goalIds.length)
console.log("Goal IDs count:", goalIds.length)
useEffect(() => {
console.log("FETCH EFFECT RAN")
async function fetch() {
const goals = await getGoals()
//console.log("GOALS FROM API:", goals?.length)
goals?.forEach((goal) => dispatch(createGoalRedux(goal)))
}
fetch()
Expand Down
28 changes: 14 additions & 14 deletions src/ui/pages/Main/transactions/TransactionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ type Props = { transaction: Transaction }
export function TransactionItem(props: Props) {
const [tags, setTags] = useState<Tag[] | null>(null)

useEffect(() => {
async function fetch(tagId: string): Promise<Tag> {
const response = await axios.get(`${API_ROOT}/api/Tag/${tagId}`)
return response.data
}
useEffect(() => {
async function fetch(tagId: string): Promise<Tag> {
const response = await axios.get(`${API_ROOT}/api/Tag/${tagId}`)
return response.data
}

async function fetchAll() {
const tags: Tag[] = []
for (const tagId of props.transaction.tagIds) {
const tag = await fetch(tagId)
tags.push(tag)
}
async function fetchAll() {
const tags: Tag[] = []

setTags(tags)
for (const tagId of props.transaction.tagIds) {
const tag = await fetch(tagId)
tags.push(tag)
}

fetchAll()
})
setTags(tags)
}

fetchAll()
}, [props.transaction.tagIds])
return (
<Container>
<Content>
Expand Down