Skip to content

Commit

Permalink
derive activeHackathon too
Browse files Browse the repository at this point in the history
  • Loading branch information
martincai8 committed Dec 1, 2024
1 parent ed6256e commit 88014b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
8 changes: 2 additions & 6 deletions src/pages/Charcuterie.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const toggleTheme = (navigate, activeHackathon) => {
}

const Charcuterie = () => {
const { activeHackathon, setActiveHackathon } = useHackathon()
const { activeHackathon } = useHackathon()
const [_, navigate] = useLocation()
const [states, setStates] = useState({
checkbox: false,
Expand All @@ -77,11 +77,7 @@ const Charcuterie = () => {
`
return (
<>
<Button
color="secondary"
width="flex"
onClick={() => toggleTheme(navigate, activeHackathon, setActiveHackathon)}
>
<Button color="secondary" width="flex" onClick={() => toggleTheme(navigate, activeHackathon)}>
Toggle Theme
</Button>
<Button color="secondary" width="flex" onClick={() => setIsLoading(!isLoading)}>
Expand Down
9 changes: 2 additions & 7 deletions src/utility/HackathonProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ function getValidHackathon(hackathon) {
export default function HackathonProvider({ children }) {
const [location] = useLocation()
const urlHackathon = location.split('/')[2]?.toLowerCase()
const [activeHackathon, setActiveHackathon] = useState(getValidHackathon(urlHackathon || ''))
const activeHackathon = getValidHackathon(urlHackathon || '')
const dbHackathonName = DB_HACKATHON_NAMES[activeHackathon]

useEffect(() => {
const newHackathon = getValidHackathon(urlHackathon || '')
setActiveHackathon(newHackathon)
}, [location])

return (
<HackathonContext.Provider value={{ activeHackathon, setActiveHackathon, dbHackathonName }}>
<HackathonContext.Provider value={{ activeHackathon, dbHackathonName }}>
{children}
</HackathonContext.Provider>
)
Expand Down

0 comments on commit 88014b2

Please sign in to comment.