diff --git a/package-lock.json b/package-lock.json
index 240aecf..94349f8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -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/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..bc1f0e1 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 } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
import 'date-fns'
@@ -12,31 +12,79 @@ import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import { Theme } from '../../components/Theme'
+// --- IMPORT EMOJI PICKER ---
+import EmojiPicker from '../../components/EmojiPicker'
+import { BaseEmoji } from 'emoji-mart'
+// --- IMPORT TRANSPARENT BUTTON ---
+import { TransparentButton } from '../../components/TransparentButton'
+
+
+const BigIcon = styled.h1`
+ font-size: 5.5rem;
+ cursor: pointer;
+`
+
+function GoalIcon({ icon, onClick }: { icon: string, onClick: (e: React.MouseEvent) => void }) {
+ return (
+
+ {icon}
+
+ )
+}
+
type Props = { goal: Goal }
+
export function GoalManager(props: Props) {
const dispatch = useAppDispatch()
-
const goal = useAppSelector(selectGoalsMap)[props.goal.id]
+ // Form state
const [name, setName] = useState(null)
const [targetDate, setTargetDate] = useState(null)
const [targetAmount, setTargetAmount] = useState(null)
-
- useEffect(() => {
- setName(props.goal.name)
- setTargetDate(props.goal.targetDate)
- setTargetAmount(props.goal.targetAmount)
- }, [
- props.goal.id,
- props.goal.name,
- props.goal.targetDate,
- props.goal.targetAmount,
- ])
+ // Icon state
+ const [icon, setIcon] = useState(props.goal.icon ?? null)
+ // Emoji picker open/close
+ const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)
useEffect(() => {
setName(goal.name)
- }, [goal.name])
+ setTargetDate(goal.targetDate)
+ setTargetAmount(goal.targetAmount)
+ setIcon(goal.icon ?? null)
+ }, [goal.id, goal.name, goal.targetDate, goal.targetAmount, goal.icon])
+
+ // Inline handlers
+ const hasIcon = () => icon != null
+
+ // --- HERE'S THE MODIFIED HANDLER ---
+ 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,
+ }
+ dispatch(updateGoalRedux(updatedGoal))
+ updateGoalApi(props.goal.id, updatedGoal)
+ }
+
+ // Add icon button
+ const addIconOnClick = (event: React.MouseEvent) => {
+ event.stopPropagation()
+ setEmojiPickerIsOpen(true)
+ }
+ // Icon click (change)
+ const iconOnClick = (event: React.MouseEvent) => {
+ event.stopPropagation()
+ setEmojiPickerIsOpen(true)
+ }
+ // Other update handlers (unchanged)
const updateNameOnChange = (event: React.ChangeEvent) => {
const nextName = event.target.value
setName(nextName)
@@ -67,7 +115,7 @@ export function GoalManager(props: Props) {
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
- targetDate: date ?? props.goal.targetDate,
+ targetDate: date,
targetAmount: targetAmount ?? props.goal.targetAmount,
}
dispatch(updateGoalRedux(updatedGoal))
@@ -78,28 +126,49 @@ export function GoalManager(props: Props) {
return (
-
+ {/* --- ICON/EMOJI ADD & CHANGE UI --- */}
+
+ {/* Show icon if exists */}
+
+ {icon && (
+
+ )}
+
+ {/* Show add icon button if missing */}
+
+
+
+ Add icon
+
+
+ {/* Emoji Picker as popover/modal */}
+ e.stopPropagation()}
+ >
+
+
+
+ {/* --- REST OF GOAL FIELDS --- */}
-
-
{props.goal.balance}
-
@@ -110,11 +179,9 @@ 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 }
+// --- FIELD AND STYLES BELOW ---
+type FieldProps = { name: string; icon: any }
const Field = (props: FieldProps) => (
@@ -122,6 +189,34 @@ const Field = (props: FieldProps) => (
)
+type AddIconButtonContainerProps = { shouldShow: boolean }
+const AddIconButtonContainer = styled.div`
+ display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
+ align-items: center;
+`
+
+type GoalIconContainerProps = { shouldShow: boolean }
+const GoalIconContainer = styled.div`
+ display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
+ align-items: center;
+ min-width: 3rem;
+ margin-right: 1rem;
+`
+
+type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean }
+const EmojiPickerContainer = styled.div`
+ display: ${(props) => (props.isOpen ? 'flex' : 'none')};
+ position: absolute;
+ top: ${(props) => (props.hasIcon ? '10rem' : '2rem')};
+ left: 0;
+ z-index: 1000;
+`
+
+const AddIconButtonText = styled.span`
+ font-size: 1.2rem;
+ margin-left: 0.5rem;
+`
+
const GoalManagerContainer = styled.div`
display: flex;
flex-direction: column;
@@ -131,7 +226,6 @@ const GoalManagerContainer = styled.div`
width: 100%;
position: relative;
`
-
const Group = styled.div`
display: flex;
flex-direction: row;
@@ -178,7 +272,8 @@ const StringInput = styled.input`
font-weight: bold;
color: ${({ theme }: { theme: Theme }) => theme.text};
`
-
const Value = styled.div`
margin-left: 2rem;
`
+
+export default GoalManager
diff --git a/src/ui/pages/Main/goals/GoalCard.tsx b/src/ui/pages/Main/goals/GoalCard.tsx
index e8f6d0a..483deb1 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,6 @@ 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