diff --git a/src/api/lib.ts b/src/api/lib.ts index 3c593ca..9af5604 100644 --- a/src/api/lib.ts +++ b/src/api/lib.ts @@ -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:5203' export async function getUser(): Promise { try { diff --git a/src/api/types.ts b/src/api/types.ts index f75edad..8cbabc0 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 } export interface Tag { diff --git a/src/ui/features/goalmanager/GoalManager.tsx b/src/ui/features/goalmanager/GoalManager.tsx index 0779dda..4c85e8f 100644 --- a/src/ui/features/goalmanager/GoalManager.tsx +++ b/src/ui/features/goalmanager/GoalManager.tsx @@ -1,5 +1,5 @@ import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons' -import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons' +import { faDollarSign, faSmile, IconDefinition } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date' import 'date-fns' @@ -11,16 +11,54 @@ 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' +import { TransparentButton } from '../../components/TransparentButton' +import GoalIcon from './GoalIcon' type Props = { goal: Goal } + + export function GoalManager(props: Props) { const dispatch = useAppDispatch() - const goal = useAppSelector(selectGoalsMap)[props.goal.id] - const [name, setName] = useState(null) const [targetDate, setTargetDate] = useState(null) const [targetAmount, setTargetAmount] = useState(null) + const [icon, setIcon] = useState(null) + const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false) + + const hasIcon = () => icon != null + + const goal = useAppSelector(selectGoalsMap)[props.goal.id] + + + const pickEmojiOnClick = (emoji: BaseEmoji, 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, + } + updateGoalApi(props.goal.id, updatedGoal) + dispatch(updateGoalRedux(updatedGoal)) + // TODO(TASK-3) Update database + } + + const addIconOnClick = (event: React.MouseEvent) => { + event.stopPropagation() + setEmojiPickerIsOpen(true) + } + + useEffect(() => { + setIcon(props.goal.icon) + }, [props.goal.id, props.goal.icon]) useEffect(() => { setName(props.goal.name) @@ -33,6 +71,7 @@ export function GoalManager(props: Props) { props.goal.targetAmount, ]) + useEffect(() => { setName(goal.name) }, [goal.name]) @@ -86,6 +125,8 @@ export function GoalManager(props: Props) { + + @@ -106,6 +147,28 @@ export function GoalManager(props: Props) { {new Date(props.goal.created).toLocaleDateString()} + + + + + Add icon + + + + + + + + + + event.stopPropagation()} + > + + + ) } @@ -115,6 +178,7 @@ type AddIconButtonContainerProps = { shouldShow: boolean } type GoalIconContainerProps = { shouldShow: boolean } type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean } + const Field = (props: FieldProps) => ( @@ -132,6 +196,10 @@ const GoalManagerContainer = styled.div` position: relative; ` +const GoalIconContainer = styled.div` + display: ${(props) => (props.shouldShow ? 'flex' : 'none')}; + ` + const Group = styled.div` display: flex; flex-direction: row; @@ -182,3 +250,26 @@ const StringInput = styled.input` const Value = styled.div` margin-left: 2rem; ` + +const EmojiPickerContainer = styled.div` + display: ${(props) => (props.isOpen ? 'flex' : 'none')}; + position: absolute; + top: ${(props) => (props.hasIcon ? '10rem' : '2rem')}; + left: 0; +` + +const AddIconButtonContainer = styled.div` + display: ${(props) => (props.shouldShow ? 'none' : 'flex')}; + position: relative; + top: 2rem; + left: 0; +` + +const AddIconButtonText = styled.span` + margin-left: 0.6rem; + font-size: 1.5rem; + color: rgba(174, 174, 174, 1); +` + + + diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx index e8f6d0a..c56e378 100644 --- a/src/ui/pages/Main/goals/GoalCard.tsx +++ b/src/ui/pages/Main/goals/GoalCard.tsx @@ -29,6 +29,7 @@ export default function GoalCard(props: Props) { ${goal.targetAmount} {asLocaleDateString(goal.targetDate)} + {goal.icon} ) } @@ -54,3 +55,7 @@ const TargetDate = styled.h4` color: rgba(174, 174, 174, 1); font-size: 1rem; ` + +const Icon = styled.h1` + font-size: 5.5rem; +`