diff --git a/src/components/Home/GoalTracker.jsx b/src/components/Home/GoalTracker.jsx new file mode 100644 index 0000000..91c0f02 --- /dev/null +++ b/src/components/Home/GoalTracker.jsx @@ -0,0 +1,213 @@ +import ExpandLessIcon from '@mui/icons-material/ExpandLess'; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; +import { + Box, + Checkbox, + CircularProgress, + Divider, + IconButton, + List, + ListItem, + ListItemText, + Paper, + Typography, +} from '@mui/material'; +import { useState } from 'react'; + +const ProgressIndicator = ({ value, size = 40, thickness = 4 }) => ( + + + + + {`${Math.round(value)}%`} + + + +); + +const Task = ({ task, onToggle }) => ( + + + + +); + +const MicroGoal = ({ microGoal, onToggleTask, onToggleExpand }) => { + const progress = + (microGoal.tasks.filter((t) => t.completed).length / microGoal.tasks.length) * 100; + + return ( + + + + {microGoal.title} + onToggleExpand(microGoal.id)} size="small" sx={{ ml: 'auto' }}> + {microGoal.expanded ? : } + + + {microGoal.expanded && ( + + {microGoal.tasks.map((task) => ( + onToggleTask(microGoal.id, task.id)} /> + ))} + + )} + + ); +}; + +const MacroGoal = ({ macroGoal, onToggleTask, onToggleExpand }) => { + const progress = + (macroGoal.microGoals.reduce((acc, mg) => acc + mg.tasks.filter((t) => t.completed).length, 0) / + macroGoal.microGoals.reduce((acc, mg) => acc + mg.tasks.length, 0)) * + 100; + + return ( + + + + + {macroGoal.title} + + onToggleExpand(macroGoal.id)} size="small" sx={{ ml: 'auto' }}> + {macroGoal.expanded ? : } + + + + {macroGoal.expanded && ( + + {macroGoal.microGoals.map((microGoal) => ( + + onToggleTask(macroGoal.id, microGoalId, taskId) + } + onToggleExpand={(microGoalId) => onToggleExpand(macroGoal.id, microGoalId)} + /> + ))} + + )} + + ); +}; + +export default function GoalTracker() { + const [goals, setGoals] = useState([ + { + id: '1', + title: 'Improve Coding Skills', + expanded: true, + microGoals: [ + { + id: '1-1', + title: 'Learn React', + expanded: true, + tasks: [ + { id: '1-1-1', title: 'Complete React tutorial', completed: true }, + { id: '1-1-2', title: 'Build a small project', completed: false }, + ], + }, + { + id: '1-2', + title: 'Master JavaScript', + expanded: false, + tasks: [ + { id: '1-2-1', title: 'Study ES6+ features', completed: false }, + { id: '1-2-2', title: 'Practice coding challenges', completed: false }, + ], + }, + ], + }, + { + id: '2', + title: 'Get Fit', + expanded: false, + microGoals: [ + { + id: '2-1', + title: 'Cardio', + expanded: false, + tasks: [ + { id: '2-1-1', title: 'Run 5k', completed: false }, + { id: '2-1-2', title: 'Swim 1k', completed: false }, + ], + }, + { + id: '2-2', + title: 'Strength Training', + expanded: false, + tasks: [ + { id: '2-2-1', title: 'Bench press 100lbs', completed: false }, + { id: '2-2-2', title: 'Squat 150lbs', completed: false }, + ], + }, + ], + }, + ]); + + const handleToggleTask = (macroGoalId, microGoalId, taskId) => { + setGoals((prevGoals) => + prevGoals.map((macroGoal) => + macroGoal.id === macroGoalId + ? { + ...macroGoal, + microGoals: macroGoal.microGoals.map((microGoal) => + microGoal.id === microGoalId + ? { + ...microGoal, + tasks: microGoal.tasks.map((task) => + task.id === taskId ? { ...task, completed: !task.completed } : task, + ), + } + : microGoal, + ), + } + : macroGoal, + ), + ); + }; + + const handleToggleExpand = (macroGoalId, microGoalId) => { + setGoals((prevGoals) => + prevGoals.map((macroGoal) => + macroGoal.id === macroGoalId + ? microGoalId + ? { + ...macroGoal, + microGoals: macroGoal.microGoals.map((microGoal) => + microGoal.id === microGoalId + ? { ...microGoal, expanded: !microGoal.expanded } + : microGoal, + ), + } + : { ...macroGoal, expanded: !macroGoal.expanded } + : macroGoal, + ), + ); + }; + + return ( + + {goals.map((macroGoal) => ( + + ))} + + ); +}