diff --git a/package-lock.json b/package-lock.json index 240aecf..0800a6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "@material-ui/core": "^4.12.4", "@material-ui/pickers": "^3.3.10", "@reduxjs/toolkit": "^1.5.1", - "@types/emoji-mart": "^3.0.5", "@types/node": "^17.0.41", "@types/react": "^16.9.0", "@types/react-redux": "^7.1.7", @@ -3703,6 +3702,7 @@ "resolved": "https://registry.npmjs.org/@types/emoji-mart/-/emoji-mart-3.0.9.tgz", "integrity": "sha512-qdBo/2Y8MXaJ/2spKjDZocuq79GpnOhkwMHnK2GnVFa8WYFgfA+ei6sil3aeWQPCreOKIx9ogPpR5+7MaOqYAA==", "dev": true, + "license": "MIT", "dependencies": { "@types/react": "*" } @@ -6611,6 +6611,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-3.0.1.tgz", "integrity": "sha512-sxpmMKxqLvcscu6mFn9ITHeZNkGzIvD0BSNFE/LJESPbCA8s1jM6bCDPjWbV31xHq7JXaxgpHxLB54RCbBZSlg==", + "license": "BSD-3-Clause", "dependencies": { "@babel/runtime": "^7.0.0", "prop-types": "^15.6.0" diff --git a/package.json b/package.json index 87958ce..b65e60e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "@material-ui/core": "^4.12.4", "@material-ui/pickers": "^3.3.10", "@reduxjs/toolkit": "^1.5.1", - "@types/emoji-mart": "^3.0.5", "@types/node": "^17.0.41", "@types/react": "^16.9.0", "@types/react-redux": "^7.1.7", @@ -59,4 +58,4 @@ "@types/react-dom": "^18.0.5", "@types/styled-components": "^5.1.25" } -} \ No newline at end of file +} diff --git a/src/App.tsx b/src/App.tsx index 5a862a6..ecdb807 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,4 @@ +import 'emoji-mart/css/emoji-mart.css'; import { createTheme, ThemeProvider as ThemeProviderMui } from '@material-ui/core' import React, { useEffect } from 'react' import styled, { ThemeProvider } from 'styled-components' diff --git a/src/api/lib.ts b/src/api/lib.ts index 3c593ca..b74e1d1 100644 --- a/src/api/lib.ts +++ b/src/api/lib.ts @@ -51,3 +51,4 @@ export async function updateGoal(goalId: string, updatedGoal: Goal): Promise(null) const [targetDate, setTargetDate] = useState(null) const [targetAmount, setTargetAmount] = useState(null) + const [selectedIcon, setSelectedIcon] = useState('🎯') + const [showEmojiPicker, setShowEmojiPicker] = useState(false) + const emojiPickerRef = useRef(null) + + // Close emoji picker when clicking outside + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (emojiPickerRef.current && !emojiPickerRef.current.contains(event.target as Node)) { + setShowEmojiPicker(false) + } + } + document.addEventListener('mousedown', handleClickOutside) + return () => document.removeEventListener('mousedown', handleClickOutside) + }, []) useEffect(() => { setName(props.goal.name) setTargetDate(props.goal.targetDate) setTargetAmount(props.goal.targetAmount) + setSelectedIcon(props.goal.icon || '🎯') + }, [ props.goal.id, props.goal.name, + props.goal.icon, props.goal.targetDate, props.goal.targetAmount, ]) @@ -75,8 +97,40 @@ export function GoalManager(props: Props) { } } + const updateIconOnSelect = (emoji: BaseEmoji, event: React.MouseEvent) => { + event.stopPropagation() + const nextIcon = emoji.native + setSelectedIcon(nextIcon) + setShowEmojiPicker(false) + const updatedGoal: Goal = { + ...props.goal, + name: name ?? props.goal.name, + targetDate: targetDate ?? props.goal.targetDate, + targetAmount: targetAmount ?? props.goal.targetAmount, + icon: nextIcon, + } + dispatch(updateGoalRedux(updatedGoal)) + updateGoalApi(props.goal.id, updatedGoal) + } + return ( + + { e.stopPropagation(); setShowEmojiPicker(!showEmojiPicker) }}> + {selectedIcon} + + {showEmojiPicker && ( + e.stopPropagation()}> + + + )} + @@ -111,9 +165,42 @@ export function GoalManager(props: Props) { } type FieldProps = { name: string; icon: IconDefinition } -type AddIconButtonContainerProps = { shouldShow: boolean } -type GoalIconContainerProps = { shouldShow: boolean } -type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean } + +const IconRow = styled.div` + display: flex; + flex-direction: row; + align-items: center; + position: relative; + margin-bottom: 0.5rem; +` + +const IconButton = styled.button` + font-size: 3rem; + background: none; + border: 2px solid transparent; + border-radius: 0.75rem; + cursor: pointer; + padding: 0.25rem 0.5rem; + transition: border-color 0.2s ease, transform 0.15s ease; + line-height: 1; + + &:hover { + border-color: rgba(174, 174, 174, 0.4); + transform: scale(1.1); + } +` + +const EmojiPickerDropdown = styled.div` + position: absolute; + top: 100%; + left: 0; + z-index: 100; + margin-top: 0.25rem; + box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.25); + border-radius: 0.75rem; + overflow: hidden; +` + const Field = (props: FieldProps) => ( diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx index e8f6d0a..a62b2e2 100644 --- a/src/ui/pages/Main/goals/GoalCard.tsx +++ b/src/ui/pages/Main/goals/GoalCard.tsx @@ -27,6 +27,10 @@ export default function GoalCard(props: Props) { return ( + {/* Add the icon here. Using a default emoji if none is set yet! */} +
+ {goal.icon ? goal.icon : '🎯'} +
${goal.targetAmount} {asLocaleDateString(goal.targetDate)}