diff --git a/src/api/lib.ts b/src/api/lib.ts index 3c593ca..1ffc18e 100644 --- a/src/api/lib.ts +++ b/src/api/lib.ts @@ -2,7 +2,8 @@ import axios from 'axios' import { user } from '../data/user' import { Goal, Transaction, User } from './types' -export const API_ROOT = 'https://fencer-commbank.azurewebsites.net' +// Update the API_ROOT to point to the local API URL +export const API_ROOT = 'http://localhost:5203' export async function getUser(): Promise { try { @@ -51,3 +52,13 @@ export async function updateGoal(goalId: string, updatedGoal: Goal): Promise { + try { + await axios.put(`${API_ROOT}/api/Goal/${goalId}`, { icon }) + return true + } catch (error: any) { + return false + } +} diff --git a/src/api/types.ts b/src/api/types.ts index f75edad..99c419a 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -27,6 +27,7 @@ export interface Goal { accountId: string transactionIds: string[] tagIds: string[] + icon: string | null // icon } export interface Tag { diff --git a/src/ui/features/goalmanager/GoalIcon.tsx b/src/ui/features/goalmanager/GoalIcon.tsx index b5a0d75..5f98775 100644 --- a/src/ui/features/goalmanager/GoalIcon.tsx +++ b/src/ui/features/goalmanager/GoalIcon.tsx @@ -14,6 +14,6 @@ export default function GoalIcon(props: Props) { } const Icon = styled.h1` - font-size: 6rem; + font-size: 5.5rem; cursor: pointer; ` diff --git a/src/ui/features/goalmanager/GoalManager.tsx b/src/ui/features/goalmanager/GoalManager.tsx index 0779dda..4f71da2 100644 --- a/src/ui/features/goalmanager/GoalManager.tsx +++ b/src/ui/features/goalmanager/GoalManager.tsx @@ -5,12 +5,14 @@ import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date' import 'date-fns' import React, { useEffect, useState } from 'react' import styled from 'styled-components' -import { updateGoal as updateGoalApi } from '../../../api/lib' +import { updateGoal as updateGoalApi, updateGoalIcon as updateGoalIconApi } from '../../../api/lib' // Added import for updateGoalIcon 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 { Theme } from '../../components/Theme' +import EmojiPicker from '../../components/EmojiPicker' // Added import for EmojiPicker +import { BaseEmoji } from 'emoji-mart' // Added import for BaseEmoji type Props = { goal: Goal } export function GoalManager(props: Props) { @@ -21,16 +23,20 @@ export function GoalManager(props: Props) { const [name, setName] = useState(null) const [targetDate, setTargetDate] = useState(null) const [targetAmount, setTargetAmount] = useState(null) + const [icon, setIcon] = useState(null) // Added state for icon + const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false) // Added state for emoji picker useEffect(() => { setName(props.goal.name) setTargetDate(props.goal.targetDate) setTargetAmount(props.goal.targetAmount) + setIcon(props.goal.icon) // Initialize icon state }, [ props.goal.id, props.goal.name, props.goal.targetDate, props.goal.targetAmount, + props.goal.icon, ]) useEffect(() => { @@ -75,6 +81,27 @@ export function GoalManager(props: Props) { } } + const pickEmojiOnClick = (emoji: BaseEmoji, event: React.MouseEvent) => { + event.stopPropagation() // Stop event propagation + + setIcon(emoji.native) // Set icon locally + setEmojiPickerIsOpen(false) // Close emoji picker + + const updatedGoal: Goal = { + ...props.goal, + icon: emoji.native ?? props.goal.icon, // Update icon in goal + name: name ?? props.goal.name, + targetDate: targetDate ?? props.goal.targetDate, + targetAmount: targetAmount ?? props.goal.targetAmount, + } + + dispatch(updateGoalRedux(updatedGoal)) // Update Redux store + + updateGoalIconApi(props.goal.id, emoji.native) // Update icon in database + } + + const hasIcon = () => icon != null + return ( @@ -106,6 +133,23 @@ export function GoalManager(props: Props) { {new Date(props.goal.created).toLocaleDateString()} + + + + + setEmojiPickerIsOpen(!emojiPickerIsOpen)}> + {icon ? {icon} : } + + + + + event.stopPropagation()} + > + + ) } @@ -182,3 +226,21 @@ const StringInput = styled.input` const Value = styled.div` margin-left: 2rem; ` + +const IconDisplay = styled.div` + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + + span { + font-size: 2rem; + } +` + +const EmojiPickerContainer = styled.div` + display: ${(props) => (props.isOpen ? 'flex' : 'none')}; + position: absolute; + top: ${(props) => (props.hasIcon ? '10rem' : '2rem')}; + left: 0; +` diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx index e8f6d0a..6aebd87 100644 --- a/src/ui/pages/Main/goals/GoalCard.tsx +++ b/src/ui/pages/Main/goals/GoalCard.tsx @@ -5,12 +5,16 @@ import { useAppDispatch, useAppSelector } from '../../../../store/hooks' import { setContent as setContentRedux, setIsOpen as setIsOpenRedux, - setType as setTypeRedux + setType as setTypeRedux, } from '../../../../store/modalSlice' import { Card } from '../../../components/Card' type Props = { id: string } +const Icon = styled.h1` + font-size: 5.5rem; +` + export default function GoalCard(props: Props) { const dispatch = useAppDispatch() @@ -29,6 +33,7 @@ export default function GoalCard(props: Props) { ${goal.targetAmount} {asLocaleDateString(goal.targetDate)} + {goal.icon} {/* Added icon display */} ) }