aboutsummaryrefslogtreecommitdiff
path: root/src/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks')
-rw-r--r--src/hooks/useNavigate.tsx42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/hooks/useNavigate.tsx b/src/hooks/useNavigate.tsx
new file mode 100644
index 0000000..0650f55
--- /dev/null
+++ b/src/hooks/useNavigate.tsx
@@ -0,0 +1,42 @@
+import React, { useState, useContext, createContext } from 'react';
+import { User } from 'which-types';
+
+export interface Page {
+ prefix: string;
+ id?: string;
+}
+
+interface ContextType {
+ page: Page;
+ setPage: (page: Page) => void;
+ navigate: (prefix: string, id?: string) => void;
+}
+
+const landingPage = { prefix: 'feed' };
+
+const context = createContext<ContextType>({
+ page: landingPage,
+ setPage: () => {},
+ navigate: () => {}
+});
+
+const useProvideNavigation = () => {
+ const [page, setPage] = useState<Page>(landingPage);
+
+ const navigate = (prefix: string, id?: string): void => {
+ setPage({ prefix, id });
+ };
+
+ return { page, setPage, navigate };
+};
+
+export const NavigationProvider: React.FC = ({ children }) => {
+ const navigation = useProvideNavigation();
+ const { Provider } = context;
+ return <Provider value={navigation}>{children}</Provider>;
+};
+
+export const useNavigate = () => {
+ return useContext(context);
+}
+