-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(layout): hide nav bar from query
Ref to #66 Mirror sites may use this to hide the nav bar when redirecting users from their home page.
- Loading branch information
1 parent
736292e
commit 9e2bf79
Showing
3 changed files
with
77 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { createContext, useContext, useState, useEffect } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const NavEnabledContext = createContext<boolean>(true); | ||
|
||
export const useNavEnabled = () => useContext(NavEnabledContext); | ||
|
||
export const NavEnableProvider = ({ children }: React.PropsWithChildren<unknown>) => { | ||
const [navEnabled, setNavEnabled] = useState<boolean>(true); | ||
|
||
const router = useRouter(); | ||
useEffect(() => { | ||
const navFromUrlQuery = router.query.nav; | ||
if (navFromUrlQuery === '0') { | ||
setNavEnabled(false); | ||
} | ||
}, [router.query.nav]); | ||
|
||
return ( | ||
<NavEnabledContext.Provider value={navEnabled}> | ||
{children} | ||
</NavEnabledContext.Provider> | ||
); | ||
}; |