-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor layout and context management
- Loading branch information
1 parent
b168c37
commit bb64c70
Showing
11 changed files
with
147 additions
and
81 deletions.
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
browser/create-template/templates/nextjs-site/next.config.mjs
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
43 changes: 0 additions & 43 deletions
43
browser/create-template/templates/nextjs-site/src/app/context/CurrentSubjectContext.tsx
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
browser/create-template/templates/nextjs-site/src/app/context/CurrentSubjectProvider.tsx
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,48 @@ | ||
import React, { | ||
createContext, | ||
SetStateAction, | ||
Dispatch, | ||
PropsWithChildren, | ||
useState, | ||
useContext, | ||
useEffect, | ||
} from 'react'; | ||
|
||
const CurrentSubjectContext = createContext<{ | ||
currentSubject: string; | ||
setCurrentSubject: Dispatch<SetStateAction<string>>; | ||
}>({ | ||
currentSubject: '', | ||
setCurrentSubject: () => '', | ||
}); | ||
|
||
export const CurrentSubjectProvider = ({ | ||
currentSubject: initialSubject, | ||
children, | ||
}: PropsWithChildren<{ currentSubject: string }>) => { | ||
const [currentSubject, setCurrentSubject] = useState(initialSubject); | ||
|
||
useEffect(() => { | ||
setCurrentSubject(initialSubject); | ||
}, [initialSubject]); | ||
|
||
return ( | ||
<CurrentSubjectContext.Provider | ||
value={{ currentSubject, setCurrentSubject }} | ||
> | ||
{children} | ||
</CurrentSubjectContext.Provider> | ||
); | ||
}; | ||
|
||
export const useCurrentSubject = () => { | ||
const context = useContext(CurrentSubjectContext); | ||
|
||
if (!context) { | ||
throw new Error( | ||
'useCurrentSubject must be used within a CurrentSubjectProvider', | ||
); | ||
} | ||
|
||
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
2 changes: 1 addition & 1 deletion
2
browser/create-template/templates/nextjs-site/src/components/Navbar.tsx
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
19 changes: 16 additions & 3 deletions
19
browser/create-template/templates/nextjs-site/src/components/ProviderWrapper.tsx
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
62 changes: 55 additions & 7 deletions
62
browser/create-template/templates/nextjs-site/src/views/MenuItem/MenuItem.tsx
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