diff --git a/src/App.jsx b/src/App.jsx
index 0d355aa..0305bdf 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -2,6 +2,7 @@ import Footer from '@/components/common/Footer'
import Header from '@/components/common/Header'
import LoadingCircle from '@/components/common/LoadingCircle'
import { UserProvider, useUser } from '@/contexts/UserContext'
+import GoalDetails from '@/pages/GoalDetails'
import Home from '@/pages/Home'
import Streak from '@/pages/Streak'
import { theme } from '@/utils/theme'
@@ -49,6 +50,10 @@ const App = () => {
path='/streak'
element={} />}
/>
+ }
+ />
diff --git a/src/components/Home/MacroGoal.jsx b/src/components/Home/MacroGoal.jsx
index a912aa4..e206bb6 100644
--- a/src/components/Home/MacroGoal.jsx
+++ b/src/components/Home/MacroGoal.jsx
@@ -1,56 +1,31 @@
-import AddItem from '@/components/Home/AddItem'
import DeleteItem from '@/components/Home/DeleteItem'
-import MicroGoal from '@/components/Home/MicroGoal'
import ProgressIndicator from '@/components/Home/ProgressIndicator'
-import useGoalsUpdater from '@/hooks/useGoalsUpdater'
import { calculateProgress } from '@/utils/calculateProgress'
-import { ExpandLess, ExpandMore } from '@mui/icons-material'
-import {
- Box,
- Collapse,
- Divider,
- IconButton,
- List,
- Paper,
- Typography,
-} from '@mui/material'
+import { Box, Paper, Typography } from '@mui/material'
+import { useNavigate } from 'react-router-dom'
const MacroGoal = ({ macroGoal, macroGoalIndex }) => {
- const { addMicrogoal, toggleGoalExpansion } = useGoalsUpdater()
const progress = calculateProgress(macroGoal.microgoals)
+ const navigate = useNavigate()
+
+ const handleNavigateToMicroGoals = () => {
+ navigate(`/goals/${macroGoalIndex}`)
+ }
return (
-
+
{macroGoal.name}
- toggleGoalExpansion(macroGoalIndex)}
- size='small'
- >
- {macroGoal.expanded ? : }
-
-
-
- addMicrogoal(macroGoalIndex, microGoalName)}
- />
-
- {macroGoal.microgoals.map((microGoal, microGoalIndex) => (
-
- ))}
-
-
)
}
diff --git a/src/components/Home/MicroGoal.jsx b/src/components/Home/MicroGoal.jsx
index d67c14e..dfb3e4b 100644
--- a/src/components/Home/MicroGoal.jsx
+++ b/src/components/Home/MicroGoal.jsx
@@ -8,6 +8,7 @@ import { ExpandLess, ExpandMore } from '@mui/icons-material'
import {
Box,
Collapse,
+ Divider,
IconButton,
List,
Paper,
@@ -15,13 +16,12 @@ import {
} from '@mui/material'
const MicroGoal = ({ microGoal, macroGoalIndex, microGoalIndex }) => {
- const { addTask, toggleMicroGoalExpansion, toggleTaskCompletion } =
- useGoalsUpdater()
+ const { addTask, toggleExpansion, toggleTaskCompletion } = useGoalsUpdater()
const progress = calculateProgress([microGoal])
return (
@@ -34,16 +34,15 @@ const MicroGoal = ({ microGoal, macroGoalIndex, microGoalIndex }) => {
microGoalIndex={microGoalIndex}
/>
- toggleMicroGoalExpansion(macroGoalIndex, microGoalIndex)
- }
+ onClick={() => toggleExpansion(macroGoalIndex, microGoalIndex)}
size='small'
>
{microGoal.expanded ? : }
-
+
+
{microGoal.tasks.map((task, taskIndex) => (
{
expect(user.goals).toContainEqual({
name: goalName,
category,
- expanded: false,
microgoals: [],
})
@@ -129,28 +128,6 @@ describe('useGoalsUpdater', () => {
)
})
- it('should toggle goal expansion', async () => {
- const goalIndex = 0
-
- // Add initial goal to user data
- user.goals.push({
- name: 'Goal 1',
- category: '#000000',
- expanded: false,
- microgoals: [],
- })
-
- await goalsUpdater.toggleGoalExpansion(goalIndex)
-
- expect(user.goals[goalIndex].expanded).toBe(true)
-
- expect(updateProfile).toHaveBeenCalledWith(
- expect.objectContaining({
- goals: user.goals,
- })
- )
- })
-
it('should toggle microgoal expansion', async () => {
const goalIndex = 0
const microGoalIndex = 0
@@ -159,11 +136,10 @@ describe('useGoalsUpdater', () => {
user.goals.push({
name: 'Goal 1',
category: '#000000',
- expanded: false,
microgoals: [{ name: 'MicroGoal 1', expanded: false, tasks: [] }],
})
- await goalsUpdater.toggleMicroGoalExpansion(goalIndex, microGoalIndex)
+ await goalsUpdater.toggleExpansion(goalIndex, microGoalIndex)
expect(user.goals[goalIndex].microgoals[microGoalIndex].expanded).toBe(true)
diff --git a/src/hooks/useGoalsUpdater/addOperations.js b/src/hooks/useGoalsUpdater/addOperations.js
index 98c49b4..eb639b5 100644
--- a/src/hooks/useGoalsUpdater/addOperations.js
+++ b/src/hooks/useGoalsUpdater/addOperations.js
@@ -6,7 +6,7 @@ import { updateGoalsAndStreak } from './updateHelpers'
export const addGoal = async (userContext, goalName, category) => {
const updatedGoals = [
...userContext.user.goals,
- { name: goalName, category, expanded: false, microgoals: [] },
+ { name: goalName, category, microgoals: [] },
]
await updateGoalsAndStreak(
userContext,
diff --git a/src/hooks/useGoalsUpdater/index.js b/src/hooks/useGoalsUpdater/index.js
index c9d751f..535011d 100644
--- a/src/hooks/useGoalsUpdater/index.js
+++ b/src/hooks/useGoalsUpdater/index.js
@@ -55,20 +55,13 @@ const useGoalsUpdater = () => {
toggleTaskCompletion: (goalIndex, microGoalIndex, taskIndex) =>
toggleTaskCompletion(userContext, goalIndex, microGoalIndex, taskIndex),
- /**
- * Toggles the expansion status of a specified goal.
- * @param {number} goalIndex - Index of the goal.
- * @returns {Promise}
- */
- toggleGoalExpansion: (goalIndex) => toggleExpansion(userContext, goalIndex),
-
/**
* Toggles the expansion status of a specified microgoal.
* @param {number} goalIndex - Index of the goal.
* @param {number} microGoalIndex - Index of the microgoal.
* @returns {Promise}
*/
- toggleMicroGoalExpansion: (goalIndex, microGoalIndex) =>
+ toggleExpansion: (goalIndex, microGoalIndex) =>
toggleExpansion(userContext, goalIndex, microGoalIndex),
}
}
diff --git a/src/hooks/useGoalsUpdater/toggleOperations.js b/src/hooks/useGoalsUpdater/toggleOperations.js
index 91f09d3..f33d23f 100644
--- a/src/hooks/useGoalsUpdater/toggleOperations.js
+++ b/src/hooks/useGoalsUpdater/toggleOperations.js
@@ -23,13 +23,10 @@ export const toggleTaskCompletion = async (
export const toggleExpansion = async (
userContext,
goalIndex,
- microGoalIndex = undefined
+ microGoalIndex
) => {
const updatedGoals = [...userContext.user.goals]
- const target =
- microGoalIndex !== undefined
- ? updatedGoals[goalIndex].microgoals[microGoalIndex]
- : updatedGoals[goalIndex]
+ const target = updatedGoals[goalIndex].microgoals[microGoalIndex]
target.expanded = !target.expanded
await updateGoalsAndStreak(
userContext,
diff --git a/src/pages/GoalDetails.jsx b/src/pages/GoalDetails.jsx
new file mode 100644
index 0000000..5686d80
--- /dev/null
+++ b/src/pages/GoalDetails.jsx
@@ -0,0 +1,57 @@
+import AddItem from '@/components/Home/AddItem'
+import MicroGoal from '@/components/Home/MicroGoal'
+import ProgressIndicator from '@/components/Home/ProgressIndicator'
+import { useUser } from '@/contexts/UserContext'
+import useGoalsUpdater from '@/hooks/useGoalsUpdater'
+import { calculateProgress } from '@/utils/calculateProgress'
+import { Box, List, Paper, Typography } from '@mui/material'
+import { useParams } from 'react-router-dom'
+
+const GoalDetails = () => {
+ const { macroGoalIndex } = useParams()
+ const { user } = useUser()
+ const { addMicrogoal } = useGoalsUpdater()
+
+ const macroGoal = user.goals[macroGoalIndex]
+ const progress = calculateProgress(macroGoal.microgoals)
+
+ return (
+
+
+
+
+
+ {macroGoal.name}
+
+
+
+
+ addMicrogoal(macroGoalIndex, microGoalName)}
+ />
+
+
+ {macroGoal.microgoals.map((microGoal, microGoalIndex) => (
+
+ ))}
+
+
+ )
+}
+
+export default GoalDetails
diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx
index d5a9830..b658e1e 100644
--- a/src/pages/Home.jsx
+++ b/src/pages/Home.jsx
@@ -9,7 +9,7 @@ const Home = () => {
const { addGoal } = useGoalsUpdater()
return (
-
+
{/* Render existing goals */}