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..47d0d91 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, IconDefinition, faSmile } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date' import 'date-fns' @@ -11,6 +11,12 @@ 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 { TransparentButton } from '../../components/TransparentButton' +import { BaseEmoji } from 'emoji-mart' +import EmojiPicker from '../../components/EmojiPicker' +import 'emoji-mart/css/emoji-mart.css' +import GoalIcon from './GoalIcon' + type Props = { goal: Goal } export function GoalManager(props: Props) { @@ -21,6 +27,8 @@ export function GoalManager(props: Props) { const [name, setName] = useState(null) const [targetDate, setTargetDate] = useState(null) const [targetAmount, setTargetAmount] = useState(null) + const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false) + const [icon, setIcon] = useState(null) useEffect(() => { setName(props.goal.name) @@ -48,6 +56,17 @@ export function GoalManager(props: Props) { updateGoalApi(props.goal.id, updatedGoal) } + useEffect(() => { + setIcon(props.goal.icon) + }, [props.goal.id, props.goal.icon]) + + const hasIcon = () => icon != null + + const addIconOnClick = (event: React.MouseEvent) => { + event.stopPropagation() + setEmojiPickerIsOpen(true) + } + const updateTargetAmountOnChange = (event: React.ChangeEvent) => { const nextTargetAmount = parseFloat(event.target.value) setTargetAmount(nextTargetAmount) @@ -75,6 +94,27 @@ export function GoalManager(props: Props) { } } + const pickEmojiOnClick = (emoji: BaseEmoji, event: React.MouseEvent) => { + // TODO(TASK-2) Stop event propogation + event.stopPropagation() + // TODO(TASK-2) Set icon locally + const selectedIcon = emoji.native || emoji.id + // TODO(TASK-2) Close emoji picker + setEmojiPickerIsOpen(false) + // TODO(TASK-2) Create updated goal locally + const updatedGoal: Goal = { + ...props.goal, + name: name ?? props.goal.name, + targetDate: targetDate ?? props.goal.targetDate, + targetAmount: targetAmount ?? props.goal.targetAmount, + icon: selectedIcon + } + // TODO(TASK-2) Update Redux store + dispatch(updateGoalRedux(updatedGoal)) + // TODO(TASK-3) Update database + updateGoalApi(props.goal.id, updatedGoal) + } + return ( @@ -106,6 +146,26 @@ export function GoalManager(props: Props) { {new Date(props.goal.created).toLocaleDateString()} + + event.stopPropagation()} + > + + + + + + + Add icon + + + + + + + ) } @@ -122,6 +182,13 @@ const Field = (props: FieldProps) => ( ) +const EmojiPickerContainer = styled.div` + display: ${(props) => (props.isOpen ? 'flex' : 'none')}; + position: absolute; + top: ${(props) => (props.hasIcon ? '10rem' : '2rem')}; + left: 0; +` + const GoalManagerContainer = styled.div` display: flex; flex-direction: column; @@ -182,3 +249,22 @@ const StringInput = styled.input` const Value = styled.div` margin-left: 2rem; ` + +const GoalIconContainer = styled.div` + display: ${(props) => (props.shouldShow ? 'flex' : 'none')}; +` + +const AddIconButtonContainer = styled.div` + display: ${(props) => (props.shouldShow ? 'flex' : 'none')}; + flex-direction: row; + align-items: center; + margin-top: 1rem; + cursor: pointer; +` + +const AddIconButtonText = styled.span` + margin-left: 0.5rem; + font-size: 1.2rem; + color: ${({ theme }: { theme: Theme }) => theme.text}; + font-weight: bold; +` \ No newline at end of file diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx index e8f6d0a..e82ec97 100644 --- a/src/ui/pages/Main/goals/GoalCard.tsx +++ b/src/ui/pages/Main/goals/GoalCard.tsx @@ -29,6 +29,8 @@ export default function GoalCard(props: Props) { ${goal.targetAmount} {asLocaleDateString(goal.targetDate)} + + {goal.icon} ) } @@ -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; +` \ No newline at end of file