Routing for all
This commit is contained in:
+7
-10
@@ -22,13 +22,11 @@ import Home from './pages/Home';
|
|||||||
import Lists from './pages/Lists';
|
import Lists from './pages/Lists';
|
||||||
import Settings from './pages/Settings';
|
import Settings from './pages/Settings';
|
||||||
import useLocation from '../hooks/useLocation';
|
import useLocation from '../hooks/useLocation';
|
||||||
|
import ListDetail from './pages/ListDetail';
|
||||||
|
|
||||||
const CurrentPage = ({ page }) => {
|
const CurrentPage = ({ page, pageProps = {} }) => {
|
||||||
const currentPage = Store.useState(selectors.getCurrentPage);
|
const currentPage = Store.useState(selectors.getCurrentPage);
|
||||||
|
|
||||||
const [match, params] = useRoute('/lists');
|
|
||||||
console.log('Matches?', match);
|
|
||||||
// const Page = currentPage.component;
|
|
||||||
const Page = page;
|
const Page = page;
|
||||||
|
|
||||||
const [local, setLocal] = useState(false);
|
const [local, setLocal] = useState(false);
|
||||||
@@ -37,18 +35,17 @@ const CurrentPage = ({ page }) => {
|
|||||||
setLocal(true);
|
setLocal(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
console.log('Rendering current page', local);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageStack>
|
<PageStack>
|
||||||
{local ? (
|
{local ? (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/" component={Home} />
|
<Route path="/" component={Home} />
|
||||||
<Route path="/lists" component={Lists} />
|
<Route path="/lists" component={Lists} />
|
||||||
|
<Route path="/lists/:listId" component={ListDetail} />
|
||||||
<Route path="/settings" component={Settings} />
|
<Route path="/settings" component={Settings} />
|
||||||
</Switch>
|
</Switch>
|
||||||
) : (
|
) : (
|
||||||
<Page selected={true} />
|
<Page selected={true} {...pageProps} />
|
||||||
)}
|
)}
|
||||||
{/*pages.map(p => {
|
{/*pages.map(p => {
|
||||||
const Page = p.component;
|
const Page = p.component;
|
||||||
@@ -59,7 +56,7 @@ const CurrentPage = ({ page }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const AppShell = ({ page }) => {
|
const AppShell = ({ page, pageProps }) => {
|
||||||
const [location, setLocation] = useLocation();
|
const [location, setLocation] = useLocation();
|
||||||
|
|
||||||
const showMenu = Store.useState(selectors.getMenuOpen);
|
const showMenu = Store.useState(selectors.getMenuOpen);
|
||||||
@@ -106,7 +103,7 @@ const AppShell = ({ page }) => {
|
|||||||
</Menu>
|
</Menu>
|
||||||
<Nav page={currentPage} />
|
<Nav page={currentPage} />
|
||||||
{/*<CurrentPage page={currentPage} />*/}
|
{/*<CurrentPage page={currentPage} />*/}
|
||||||
<CurrentPage page={page} />
|
<CurrentPage page={page} pageProps={pageProps} />
|
||||||
<TabBar>
|
<TabBar>
|
||||||
<Tab
|
<Tab
|
||||||
icon={homeOutline}
|
icon={homeOutline}
|
||||||
@@ -120,7 +117,7 @@ const AppShell = ({ page }) => {
|
|||||||
selectedIcon={list}
|
selectedIcon={list}
|
||||||
title="Lists"
|
title="Lists"
|
||||||
href="/lists"
|
href="/lists"
|
||||||
selected={'/lists' === location}
|
selected={location.indexOf('/lists') === 0}
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
icon={cogOutline}
|
icon={cogOutline}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const Home = ({ selected }) => {
|
|||||||
const homeItems = Store.useState(selectors.getHomeItems);
|
const homeItems = Store.useState(selectors.getHomeItems);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content visible={true} className="p-4 dark:bg-black">
|
<Content className="p-4 dark:bg-black">
|
||||||
{homeItems.map((i, index) => (
|
{homeItems.map((i, index) => (
|
||||||
<HomeCard {...i} key={index} />
|
<HomeCard {...i} key={index} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import { Link } from 'wouter';
|
||||||
|
|
||||||
|
import usePage from '../../hooks/usePage';
|
||||||
|
import { lists } from '../../mock';
|
||||||
import Store from '../../store';
|
import Store from '../../store';
|
||||||
import * as actions from '../../store/actions';
|
import * as actions from '../../store/actions';
|
||||||
import * as selectors from '../../store/selectors';
|
import * as selectors from '../../store/selectors';
|
||||||
@@ -6,13 +10,11 @@ import Content from '../ui/Content';
|
|||||||
import List from '../ui/List';
|
import List from '../ui/List';
|
||||||
import VirtualScroll from '../ui/VirtualScroll';
|
import VirtualScroll from '../ui/VirtualScroll';
|
||||||
|
|
||||||
const ListItems = ({ list, onClose }) => {
|
const ListItems = ({ list }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="py-2">
|
<div className="py-2">
|
||||||
<a href="#" onClick={onClose}>
|
<Link href="/lists">All Lists</Link>
|
||||||
All Lists
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
<VirtualScroll
|
<VirtualScroll
|
||||||
data={list?.items || []}
|
data={list?.items || []}
|
||||||
@@ -39,27 +41,19 @@ const ListItemEntry = ({ list, item }) => (
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ListDetail = ({ selected }) => {
|
const ListDetail = ({ selected, list, listId, params }) => {
|
||||||
const selectedList = Store.useState(selectors.getSelectedList);
|
const selectedList = Store.useState(selectors.getSelectedList);
|
||||||
|
|
||||||
|
const loadedList = list ? list : lists.find(l => l.id === params.listId);
|
||||||
|
|
||||||
usePage({
|
usePage({
|
||||||
title: selectedList.title,
|
title: loadedList.title,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content visible={selected} className="p-4">
|
<Content className="p-4">
|
||||||
<List className="h-full w-full">
|
<List className="h-full w-full">
|
||||||
{selected && (
|
<ListItems list={loadedList} />
|
||||||
<ListItems
|
|
||||||
list={selectedList}
|
|
||||||
onClose={() => {
|
|
||||||
/*
|
|
||||||
actions.setSelectedList(null);
|
|
||||||
actions.setPageById('lists');
|
|
||||||
*/
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</List>
|
</List>
|
||||||
</Content>
|
</Content>
|
||||||
);
|
);
|
||||||
|
|||||||
+13
-20
@@ -1,3 +1,5 @@
|
|||||||
|
import { Link } from 'wouter';
|
||||||
|
|
||||||
import usePage from '../../hooks/usePage';
|
import usePage from '../../hooks/usePage';
|
||||||
import Store from '../../store';
|
import Store from '../../store';
|
||||||
import * as actions from '../../store/actions';
|
import * as actions from '../../store/actions';
|
||||||
@@ -8,12 +10,14 @@ import List from '../ui/List';
|
|||||||
import VirtualScroll from '../ui/VirtualScroll';
|
import VirtualScroll from '../ui/VirtualScroll';
|
||||||
|
|
||||||
const ListEntry = ({ list, ...props }) => (
|
const ListEntry = ({ list, ...props }) => (
|
||||||
<div
|
<Link href={`/lists/${list.id}`}>
|
||||||
{...props}
|
<a
|
||||||
className="p-4 border-solid dark:border-gray-800 border-b cursor-pointer dark:text-gray-200"
|
{...props}
|
||||||
>
|
className="p-4 border-solid dark:border-gray-800 border-b cursor-pointer dark:text-gray-200 block"
|
||||||
<span className="text-md">{list.name}</span>
|
>
|
||||||
</div>
|
<span className="text-md">{list.name}</span>
|
||||||
|
</a>
|
||||||
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
||||||
const AllLists = ({ onSelect }) => {
|
const AllLists = ({ onSelect }) => {
|
||||||
@@ -24,9 +28,7 @@ const AllLists = ({ onSelect }) => {
|
|||||||
data={lists}
|
data={lists}
|
||||||
totalCount={lists.length}
|
totalCount={lists.length}
|
||||||
style={{ height: '100%', width: '100%' }}
|
style={{ height: '100%', width: '100%' }}
|
||||||
itemContent={(i, list) => (
|
itemContent={(i, list) => <ListEntry list={list} />}
|
||||||
<ListEntry list={list} onClick={() => onSelect(list)} onClose={() => onSelect(null)} />
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -37,18 +39,9 @@ const Lists = ({ selected }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content visible={true} className="p-4 dark:bg-black">
|
<Content className="p-4 dark:bg-black">
|
||||||
<List className="h-full w-full">
|
<List className="h-full w-full">
|
||||||
{/*selected && (*/}
|
<AllLists />
|
||||||
<AllLists
|
|
||||||
onSelect={list => {
|
|
||||||
/*
|
|
||||||
actions.setSelectedList(list);
|
|
||||||
actions.setPageById('list-detail');
|
|
||||||
*/
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{/*)}*/}
|
|
||||||
</List>
|
</List>
|
||||||
</Content>
|
</Content>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const Settings = ({ selected }) => {
|
|||||||
const settings = Store.useState(selectors.getSettings);
|
const settings = Store.useState(selectors.getSettings);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content visible={true} className="p-4 dark:bg-black">
|
<Content className="p-4 dark:bg-black">
|
||||||
<List>
|
<List>
|
||||||
<ListItem className="flex">
|
<ListItem className="flex">
|
||||||
<span className="text-md flex-1 dark:text-gray-200">Enable Notifications</span>
|
<span className="text-md flex-1 dark:text-gray-200">Enable Notifications</span>
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
const Content = ({ className, visible, children, ...props }) => (
|
const Content = ({ className, children, ...props }) => (
|
||||||
<div
|
<div
|
||||||
{...props}
|
{...props}
|
||||||
className={classNames(`h-full w-full overflow-auto py-2 absolute top-0`, className, {
|
className={classNames(`h-full w-full overflow-auto py-2 absolute top-0`, className)}
|
||||||
visible,
|
|
||||||
invisible: !visible,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Some fake lists
|
||||||
|
const lists = [
|
||||||
|
{
|
||||||
|
name: 'Groceries',
|
||||||
|
id: 'groceries',
|
||||||
|
items: [{ name: 'Apples' }, { name: 'Bananas' }, { name: 'Milk' }, { name: 'Ice Cream' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Hardware Store',
|
||||||
|
id: 'hardware',
|
||||||
|
items: [
|
||||||
|
{ name: 'Circular Saw' },
|
||||||
|
{ name: 'Tack Cloth' },
|
||||||
|
{ name: 'Drywall' },
|
||||||
|
{ name: 'Router' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ name: 'Work', id: 'work', items: [{ name: 'TPS Report' }, { name: 'Set up email' }] },
|
||||||
|
{ name: 'Reminders', id: 'reminders' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export { lists };
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import AppShell from '../../components/AppShell';
|
||||||
|
import ListDetailPage from '../../components/pages/ListDetail';
|
||||||
|
import { lists } from '../../mock';
|
||||||
|
|
||||||
|
export default function ListDetail({ list }) {
|
||||||
|
return <AppShell page={ListDetailPage} pageProps={{ list }} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getServerSideProps = context => {
|
||||||
|
const {
|
||||||
|
params: { listId },
|
||||||
|
} = context;
|
||||||
|
|
||||||
|
const list = lists.find(l => l.id === listId);
|
||||||
|
console.log('Loaded list', list);
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
list,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
+2
-21
@@ -1,5 +1,7 @@
|
|||||||
import { Store as PullStateStore } from 'pullstate';
|
import { Store as PullStateStore } from 'pullstate';
|
||||||
|
|
||||||
|
import { lists } from '../mock';
|
||||||
|
|
||||||
import { list, listOutline, cog, cogOutline, home, homeOutline } from 'ionicons/icons';
|
import { list, listOutline, cog, cogOutline, home, homeOutline } from 'ionicons/icons';
|
||||||
|
|
||||||
import Home from '../components/pages/Home';
|
import Home from '../components/pages/Home';
|
||||||
@@ -39,27 +41,6 @@ export const homeItems = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// Some fake lists
|
|
||||||
const lists = [
|
|
||||||
{
|
|
||||||
name: 'Groceries',
|
|
||||||
id: 'groceries',
|
|
||||||
items: [{ name: 'Apples' }, { name: 'Bananas' }, { name: 'Milk' }, { name: 'Ice Cream' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Hardware Store',
|
|
||||||
id: 'hardware',
|
|
||||||
items: [
|
|
||||||
{ name: 'Circular Saw' },
|
|
||||||
{ name: 'Tack Cloth' },
|
|
||||||
{ name: 'Drywall' },
|
|
||||||
{ name: 'Router' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ name: 'Work', id: 'work', items: [{ name: 'TPS Report' }, { name: 'Set up email' }] },
|
|
||||||
{ name: 'Reminders', id: 'reminders' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const Store = new PullStateStore({
|
const Store = new PullStateStore({
|
||||||
safeAreaTop: 0,
|
safeAreaTop: 0,
|
||||||
safeAreaBottom: 0,
|
safeAreaBottom: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user