Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use url instead of localstorage #651

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function App() {

useEffect(() => {
if (location === '/') {
localStorage.removeItem('activeHackathon')
document.title = 'Hacker Portal'
}
}, [location])
Expand Down
2 changes: 0 additions & 2 deletions src/components/HackathonCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ const HackathonCard = ({
isUpNext,
}) => {
const [_, navigate] = useLocation()
const { setActiveHackathon } = useHackathon()

return (
<StyledHackathonCard background={background} isUpNext={isUpNext}>
Expand Down Expand Up @@ -247,7 +246,6 @@ const HackathonCard = ({
color={buttonColour}
labelColor={buttonTextColour}
onClick={() => {
setActiveHackathon(hackathonName.toLowerCase())
handleNavigation(applicationOpen, visitWebsite, hackathonName, navigate)
}}
hoverColor={buttonHoverColor}
Expand Down
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
16 changes: 6 additions & 10 deletions src/utility/HackathonProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createContext, useContext, useState, useEffect } from 'react'
import { useLocation } from 'wouter'
import { DB_HACKATHON_NAMES, VALID_HACKATHONS } from './Constants'

const HackathonContext = createContext()
Expand All @@ -12,18 +13,13 @@ function getValidHackathon(hackathon) {
}

export default function HackathonProvider({ children }) {
const storedHackathon = localStorage.getItem('activeHackathon')
const initialHackathon = getValidHackathon(storedHackathon || '')
const [activeHackathon, setActiveHackathon] = useState(initialHackathon)
const [dbHackathonName, setDbHackathonName] = useState(DB_HACKATHON_NAMES[initialHackathon])

useEffect(() => {
localStorage.setItem('activeHackathon', activeHackathon)
setDbHackathonName(DB_HACKATHON_NAMES[activeHackathon])
}, [activeHackathon])
const [location] = useLocation()
const urlHackathon = location.split('/')[2]?.toLowerCase()
const activeHackathon = getValidHackathon(urlHackathon || '')
const dbHackathonName = DB_HACKATHON_NAMES[activeHackathon]

return (
<HackathonContext.Provider value={{ activeHackathon, setActiveHackathon, dbHackathonName }}>
<HackathonContext.Provider value={{ activeHackathon, dbHackathonName }}>
{children}
</HackathonContext.Provider>
)
Expand Down
8 changes: 0 additions & 8 deletions src/utility/Routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ import { useHackathon } from './HackathonProvider'
const NestedRoutes = props => {
const router = useRouter()
const [location] = useLocation()
const { activeHackathon, setActiveHackathon } = useHackathon()
const hackathonFromURL = props.base.split('/')[2].toLowerCase()

useEffect(() => {
if (VALID_HACKATHONS.includes(hackathonFromURL)) {
setActiveHackathon(hackathonFromURL)
localStorage.setItem('activeHackathon', activeHackathon)
}
}, [props.base, activeHackathon, setActiveHackathon])

if (!location.startsWith(props.base)) return null

if (!VALID_HACKATHONS.includes(hackathonFromURL)) {
Expand Down