From 1499c0126d1a7a2377b0267b761479100c636ee9 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Tue, 30 Jun 2020 00:41:09 +0300
Subject: feat!: create useNavigate hook

---
 src/hooks/useNavigate.tsx | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 src/hooks/useNavigate.tsx

(limited to 'src/hooks/useNavigate.tsx')

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);
+}
+
-- 
cgit v1.2.3


From 5ccb1ec0be71ed4efb22b4942d70d9132415f69e Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Tue, 30 Jun 2020 00:43:48 +0300
Subject: style: fix some eslint errors

---
 src/hooks/useNavigate.tsx | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'src/hooks/useNavigate.tsx')

diff --git a/src/hooks/useNavigate.tsx b/src/hooks/useNavigate.tsx
index 0650f55..9513f13 100644
--- a/src/hooks/useNavigate.tsx
+++ b/src/hooks/useNavigate.tsx
@@ -1,5 +1,4 @@
 import React, { useState, useContext, createContext } from 'react';
-import { User } from 'which-types';
 
 export interface Page {
   prefix: string;
@@ -38,5 +37,5 @@ export const NavigationProvider: React.FC = ({ children }) => {
 
 export const useNavigate = () => {
   return useContext(context);
-}
+};
 
-- 
cgit v1.2.3


From e170d04d5d2c8c86d2683f3accb4feb2d94c881a Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Tue, 30 Jun 2020 01:34:51 +0300
Subject: style: fix linting errors

---
 src/hooks/useNavigate.tsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/hooks/useNavigate.tsx')

diff --git a/src/hooks/useNavigate.tsx b/src/hooks/useNavigate.tsx
index 9513f13..befc529 100644
--- a/src/hooks/useNavigate.tsx
+++ b/src/hooks/useNavigate.tsx
@@ -22,7 +22,7 @@ const context = createContext<ContextType>({
 const useProvideNavigation = () => {
   const [page, setPage] = useState<Page>(landingPage);
 
-  const navigate = (prefix: string, id?: string): void => {
+  const navigate: ContextType['navigate'] = (prefix, id?) => {
     setPage({ prefix, id });
   };
 
@@ -35,7 +35,7 @@ export const NavigationProvider: React.FC = ({ children }) => {
   return <Provider value={navigation}>{children}</Provider>;
 };
 
-export const useNavigate = () => {
+export const useNavigate = (): ContextType => {
   return useContext(context);
 };
 
-- 
cgit v1.2.3

