diff --git a/components/AppShell.jsx b/components/AppShell.jsx
index 0de06ba..ce0347f 100644
--- a/components/AppShell.jsx
+++ b/components/AppShell.jsx
@@ -1,5 +1,7 @@
+import { useCallback, useEffect, useState } from 'react';
import { useDrag } from 'react-use-gesture';
-import { Route, Switch } from 'wouter';
+import { Router, Route, Switch, useRoute } from 'wouter';
+import { cog, cogOutline, home, homeOutline, list, listOutline } from 'ionicons/icons';
import Store from '../store';
import * as actions from '../store/actions';
@@ -16,13 +18,16 @@ import TabBar from '../components/ui/TabBar';
import { SafeAreaProvider } from '../components/ui/SafeArea';
import Notifications from '../components/Notifications';
import MenuContent from '../components/MenuContent';
-import { useEffect, useState } from 'react';
import Home from './pages/Home';
-import { cog, cogOutline, home, homeOutline, list, listOutline } from 'ionicons/icons';
+import Lists from './pages/Lists';
+import Settings from './pages/Settings';
+import useLocation from '../hooks/useLocation';
const CurrentPage = ({ page }) => {
const currentPage = Store.useState(selectors.getCurrentPage);
+ const [match, params] = useRoute('/lists');
+ console.log('Matches?', match);
// const Page = currentPage.component;
const Page = page;
@@ -32,19 +37,23 @@ const CurrentPage = ({ page }) => {
setLocal(true);
}, []);
+ console.log('Rendering current page', local);
+
return (
{local ? (
+
+
) : (
)}
{/*pages.map(p => {
- const Page = p.component;
- return ;
- })*/}
+ const Page = p.component;
+ return ;
+ })*/}
{/**/}
);
@@ -87,39 +96,41 @@ const AppShell = ({ page }) => {
}}
>
-
-
- {/**/}
-
-
- actions.setPage(p)}
- selected={'home' === currentPage?.id}
- />
- actions.setPage(p)}
- selected={'lists' === currentPage?.id}
- />
- actions.setPage(p)}
- selected={'settings' === currentPage?.id}
- />
-
-
-
-
-
+
+
+
+ {/**/}
+
+
+
+
+
+
+
+
+
+
+
);
diff --git a/components/pages/Lists.jsx b/components/pages/Lists.jsx
index 584b076..465d61c 100644
--- a/components/pages/Lists.jsx
+++ b/components/pages/Lists.jsx
@@ -7,7 +7,10 @@ import List from '../ui/List';
import VirtualScroll from '../ui/VirtualScroll';
const ListEntry = ({ list, ...props }) => (
-
+
{list.name}
);
@@ -29,7 +32,7 @@ const AllLists = ({ onSelect }) => {
const Lists = ({ selected }) => {
return (
-
+
{selected && (
{
const settings = Store.useState(selectors.getSettings);
return (
-
+
Enable Notifications
diff --git a/components/ui/Tab.jsx b/components/ui/Tab.jsx
index c78ed0e..5775478 100644
--- a/components/ui/Tab.jsx
+++ b/components/ui/Tab.jsx
@@ -1,24 +1,27 @@
import classNames from 'classnames';
import Icon from './Icon';
+import { Link } from 'wouter';
-const Tab = ({ title, icon, selected, selectedIcon, onClick }) => (
-
- {icon && (
-
- )}
-
-
+const Tab = ({ title, href, icon, selected, selectedIcon, onClick }) => (
+
+
+ {icon && (
+
+ )}
+
+
+
);
export default Tab;
diff --git a/hooks/useLocation.js b/hooks/useLocation.js
new file mode 100644
index 0000000..a396f0d
--- /dev/null
+++ b/hooks/useLocation.js
@@ -0,0 +1,86 @@
+import { useEffect, useRef, useState, useCallback } from 'react';
+
+/**
+ * History API docs @see https://developer.mozilla.org/en-US/docs/Web/API/History
+ */
+const eventPopstate = 'popstate';
+const eventPushState = 'pushState';
+const eventReplaceState = 'replaceState';
+export const events = [eventPopstate, eventPushState, eventReplaceState];
+
+const useLocation = ({ base = '' } = {}) => {
+ const getCurrentPathname = useCallback(base => {
+ const path = typeof location === 'undefined' ? '/' : location.pathname;
+
+ return !path.toLowerCase().indexOf(base.toLowerCase())
+ ? path.slice(base.length) || '/'
+ : '~' + path;
+ }, []);
+
+ const [path, update] = useState(() => getCurrentPathname(base)); // @see https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
+ const prevPath = useRef(path);
+
+ useEffect(() => {
+ // While History API does have `popstate` event, the only
+ // proper way to listen to changes via `push/replaceState`
+ // is to monkey-patch these methods.
+ //
+ // See https://stackoverflow.com/a/4585031
+ if (typeof history !== 'undefined') {
+ for (const type of [eventPushState, eventReplaceState]) {
+ const original = history[type];
+
+ history[type] = function () {
+ const result = original.apply(this, arguments);
+ const event = new Event(type);
+ event.arguments = arguments;
+
+ dispatchEvent(event);
+ return result;
+ };
+ }
+ } else {
+ console.log('No history API');
+ }
+ });
+
+ useEffect(() => {
+ // this function checks if the location has been changed since the
+ // last render and updates the state only when needed.
+ // unfortunately, we can't rely on `path` value here, since it can be stale,
+ // that's why we store the last pathname in a ref.
+ const checkForUpdates = () => {
+ const pathname = getCurrentPathname(base);
+ console.log('CHECK FOR UPDATES', pathname);
+ prevPath.current !== pathname && update((prevPath.current = pathname));
+ };
+
+ events.map(e => addEventListener(e, checkForUpdates));
+
+ // it's possible that an update has occurred between render and the effect handler,
+ // so we run additional check on mount to catch these updates. Based on:
+ // https://gist.github.com/bvaughn/e25397f70e8c65b0ae0d7c90b731b189
+ checkForUpdates();
+
+ return () => events.map(e => removeEventListener(e, checkForUpdates));
+ }, [base]);
+
+ // the 2nd argument of the `useLocation` return value is a function
+ // that allows to perform a navigation.
+ //
+ // the function reference should stay the same between re-renders, so that
+ // it can be passed down as an element prop without any performance concerns.
+ const navigate = useCallback(
+ (to, { replace = false } = {}) =>
+ history[replace ? eventReplaceState : eventPushState](
+ null,
+ '',
+ // handle nested routers and absolute paths
+ to[0] === '~' ? to.slice(1) : base + to
+ ),
+ [base]
+ );
+
+ return [path, navigate];
+};
+export default useLocation;
diff --git a/pages/lists.js b/pages/lists.js
new file mode 100644
index 0000000..cbbc0ba
--- /dev/null
+++ b/pages/lists.js
@@ -0,0 +1,6 @@
+import AppShell from '../components/AppShell';
+import ListsPage from '../components/pages/Lists';
+
+export default function Lists() {
+ return ;
+}
diff --git a/pages/settings.js b/pages/settings.js
new file mode 100644
index 0000000..89dcf95
--- /dev/null
+++ b/pages/settings.js
@@ -0,0 +1,6 @@
+import AppShell from '../components/AppShell';
+import SettingsPage from '../components/pages/Settings';
+
+export default function Settings() {
+ return ;
+}