-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: UseContext to ftch navMap Data
- Loading branch information
1 parent
aa31fb8
commit c080eea
Showing
10 changed files
with
84 additions
and
205 deletions.
There are no files selected for viewing
Empty file.
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
112 changes: 0 additions & 112 deletions
112
src/components/navigation/NavMenu/Megamenu/menuItems.tsx
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
export type NavItem = { | ||
title: string; | ||
link: string; | ||
}; | ||
|
||
export type NavMap = { | ||
title: string; | ||
videoUrl: string; | ||
items: NavItem[]; | ||
}; |
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 { NavMap } from '@datatypes/NavMap'; | ||
import React from 'react'; | ||
|
||
interface NavMapContextValue { | ||
data?: NavMap[]; | ||
fetchData: () => Promise<void>; | ||
} | ||
|
||
export const NavMapContext = React.createContext<NavMapContextValue>({ | ||
fetchData: async () => {}, | ||
}); | ||
|
||
interface NavMapProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export const NavMapProvider: React.FC<NavMapProviderProps> = ({ children }) => { | ||
const [data, setData] = React.useState<NavMap[]>(); | ||
|
||
const fetchData = React.useCallback(async () => { | ||
const response = await fetch('/api/website/navigation-map'); | ||
const data = await response.json(); | ||
setData(data); | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
fetchData(); | ||
}, [fetchData]); | ||
|
||
return ( | ||
<NavMapContext.Provider value={{ data, fetchData }}> | ||
{children} | ||
</NavMapContext.Provider> | ||
); | ||
}; | ||
|
||
export const useNavMapContext = () => React.useContext(NavMapContext); |
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 was deleted.
Oops, something went wrong.