-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2044 from tijlleenders/vin/-/fix-hints
fix: hints option not updating correctly and hints section not visible in subggoal list
- Loading branch information
Showing
11 changed files
with
253 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { GoalItem } from "@src/models/GoalItem"; | ||
import React, { ReactNode, createContext, useContext, useEffect, useMemo, useState } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
type AvailableGoalHintContext = { | ||
goal: GoalItem | undefined; | ||
setGoal: React.Dispatch<React.SetStateAction<GoalItem | undefined>>; | ||
}; | ||
|
||
export const AvailableGoalHintContext = createContext<AvailableGoalHintContext | undefined>(undefined); | ||
|
||
export const AvailableGoalHintProvider = ({ children, goalHints }: { children: ReactNode; goalHints: GoalItem[] }) => { | ||
const { activeGoalId, partnerId } = useParams(); | ||
const [goal, setGoal] = useState<GoalItem>(); | ||
const isPartnerModeActive = !!partnerId; | ||
|
||
useEffect(() => { | ||
if (activeGoalId) { | ||
const hint = goalHints.find((goalItem) => { | ||
return goalItem.id === activeGoalId; | ||
}); | ||
setGoal(hint); | ||
} | ||
}, [isPartnerModeActive, activeGoalId]); | ||
|
||
const value = useMemo(() => ({ goal, setGoal }), [goal]); | ||
|
||
return <AvailableGoalHintContext.Provider value={value}>{children}</AvailableGoalHintContext.Provider>; | ||
}; | ||
|
||
export const useAvailableGoalHintContext = () => { | ||
const context = useContext(AvailableGoalHintContext); | ||
if (!context) { | ||
throw new Error("useAvailableGoalHintContext must be used within a AvailableGoalHintContext"); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.