diff --git a/src/components/Home/AddItem.jsx b/src/components/Home/AddItem.jsx index 112814b..43c4451 100644 --- a/src/components/Home/AddItem.jsx +++ b/src/components/Home/AddItem.jsx @@ -1,27 +1,51 @@ +// @ts-check + +import CategoryPicker from '@/components/Home/CategoryPicker' import AddIcon from '@mui/icons-material/Add' import { IconButton, InputAdornment, TextField } from '@mui/material' import { useState } from 'react' const AddItem = ({ label, onAdd }) => { const [inputValue, setInputValue] = useState('') + const [selectedCategory, setSelectedCategory] = useState('#000000') const handleAdd = async () => { if (inputValue.trim()) { - await onAdd(inputValue) + await onAdd( + inputValue.trim(), + label === 'New Goal' ? selectedCategory : null + ) setInputValue('') + setSelectedCategory('#000000') } } + // Conditionally render the category picker + const startAdornment = + label === 'New Goal' ? ( + + ) : null + return ( setInputValue(e.target.value)} - fullWidth onKeyDown={(e) => e.key === 'Enter' && handleAdd()} + fullWidth slotProps={{ input: { + startAdornment, endAdornment: ( ( + +) + +const CategoryPicker = ({ selectedCategory, setSelectedCategory }) => ( + + + +) + +export default CategoryPicker diff --git a/src/hooks/useGoalsUpdater.js b/src/hooks/useGoalsUpdater.js index e0184e2..c596042 100644 --- a/src/hooks/useGoalsUpdater.js +++ b/src/hooks/useGoalsUpdater.js @@ -7,8 +7,8 @@ const useGoalsUpdater = () => { // Function to update both goals and optionally streak in the user profile const updateGoalsAndStreak = async ( updatedGoals, - countChange = 0, - message + message, + countChange = 0 ) => { try { // If countChange is not 0, update the streak days @@ -97,8 +97,8 @@ const useGoalsUpdater = () => { await updateGoalsAndStreak( updatedGoals, - task.completed ? 1 : -1, - 'Task completion status toggled successfully.' + 'Task completion status toggled successfully.', + task.completed ? 1 : -1 ) } @@ -125,9 +125,16 @@ const useGoalsUpdater = () => { } return { - // Add new goal, microgoal, or task - addGoal: (goalName) => - addItem({ name: goalName, expanded: false, microgoals: [] }, 'goal'), + addGoal: (goalName, category) => + addItem( + { + name: goalName, + category: category, // Store only category name + expanded: false, + microgoals: [], + }, + 'goal' + ), addMicrogoal: (goalIndex, microGoalName) => addItem( { name: microGoalName, expanded: false, tasks: [] }, diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 2ae0e43..d5a9830 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -11,10 +11,22 @@ const Home = () => { return ( - - {user.goals.map((macroGoal, index) => ( - - ))} + + {/* Render existing goals */} + + {user.goals.map((goal, index) => ( + + + + ))} + ) }