Refactor state and make list detail a page

This commit is contained in:
Max Lynch
2020-12-24 15:56:08 -06:00
parent 0056d6fe81
commit 06c1a8f71d
12 changed files with 182 additions and 115 deletions
+14 -11
View File
@@ -1,4 +1,6 @@
import Store from '../store';
import * as actions from '../store/actions';
import * as selectors from '../store/selectors';
const MenuItem = ({ children, ...props }) => (
<li {...props}>
@@ -12,14 +14,11 @@ const MenuItem = ({ children, ...props }) => (
);
const MenuContent = () => {
const pages = Store.useState(s => s.pages);
const menuLinks = Store.useState(selectors.getMenuLinks);
const go = page => {
Store.update(s => {
console.log('Going to', page);
s.currentPage = page;
s.showMenu = false;
});
actions.setPage(page);
actions.setMenuOpen(false);
};
return (
@@ -28,11 +27,15 @@ const MenuContent = () => {
<h2 className="text-xl select-none">Menu</h2>
</div>
<ul>
{pages.map(p => (
<MenuItem key={p.id} onClick={() => go(p)}>
{p.title}
</MenuItem>
))}
{menuLinks.map(p => {
const title = typeof p.title === 'function' ? p.title() : p.title;
return (
<MenuItem key={p.id} onClick={() => go(p)}>
{title}
</MenuItem>
);
})}
</ul>
</>
);