Moving to a todo app
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { Virtuoso } from 'react-virtuoso';
|
||||
|
||||
import Content from '../ui/Content';
|
||||
import List from '../ui/List';
|
||||
import ListItem from '../ui/ListItem';
|
||||
|
||||
const Feed = ({ selected }) => {
|
||||
return (
|
||||
<Content visible={selected} className="p-4">
|
||||
<List className="h-full w-full">
|
||||
{selected && (
|
||||
<Virtuoso
|
||||
totalCount={1000}
|
||||
overscan={200}
|
||||
style={{ height: '100%', width: '100%' }}
|
||||
itemContent={index => <ListItem>Item {index}</ListItem>}
|
||||
/>
|
||||
)}
|
||||
</List>
|
||||
</Content>
|
||||
);
|
||||
};
|
||||
|
||||
export default Feed;
|
||||
@@ -1,14 +1,12 @@
|
||||
import { homeItems } from '../../data';
|
||||
import Store from '../../store';
|
||||
import Card from '../ui/Card';
|
||||
import Content from '../ui/Content';
|
||||
|
||||
const PostCard = ({ title, type, text, author, image }) => (
|
||||
<Card>
|
||||
const HomeCard = ({ title, type, text, author, image }) => (
|
||||
<Card className="my-4">
|
||||
<div>
|
||||
<img
|
||||
className="rounded-t-xl h-32 w-full object-cover"
|
||||
src={image || 'https://ionic-docs-demo.herokuapp.com/assets/card-top-img.png'}
|
||||
/>
|
||||
<img className="rounded-t-xl h-32 w-full object-cover" src={image} />
|
||||
</div>
|
||||
<div className="px-4 py-4 mt-2 bg-white rounded-b-xl">
|
||||
<h4 className="font-bold py-0 text-s text-gray-400 uppercase">{type}</h4>
|
||||
@@ -19,10 +17,12 @@ const PostCard = ({ title, type, text, author, image }) => (
|
||||
);
|
||||
|
||||
const Home = ({ selected }) => {
|
||||
const homeItems = Store.useState(s => s.homeItems);
|
||||
|
||||
return (
|
||||
<Content visible={selected}>
|
||||
<Content visible={selected} className="p-4">
|
||||
{homeItems.map((i, index) => (
|
||||
<PostCard {...i} key={index} />
|
||||
<HomeCard {...i} key={index} />
|
||||
))}
|
||||
</Content>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { useState } from 'react';
|
||||
import Store from '../../store';
|
||||
import { setDone } from '../../store/actions';
|
||||
import Card from '../ui/Card';
|
||||
|
||||
import Content from '../ui/Content';
|
||||
import List from '../ui/List';
|
||||
import ListItem from '../ui/ListItem';
|
||||
import VirtualScroll from '../ui/VirtualScroll';
|
||||
|
||||
const ListEntry = ({ list, ...props }) => (
|
||||
<div {...props} className="p-4 border-solid border-b cursor-pointer">
|
||||
<span className="text-md">{list.name}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const AllLists = ({ onSelect }) => {
|
||||
const lists = Store.useState(s => s.lists);
|
||||
|
||||
return (
|
||||
<VirtualScroll
|
||||
data={lists}
|
||||
totalCount={lists.length}
|
||||
style={{ height: '100%', width: '100%' }}
|
||||
itemContent={(i, list) => (
|
||||
<ListEntry list={list} onClick={() => onSelect(list)} onClose={() => onSelect(null)} />
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const ListItems = ({ list, onClose }) => {
|
||||
return (
|
||||
<>
|
||||
<div className="py-2">
|
||||
<a href="#" onClick={onClose}>
|
||||
All Lists
|
||||
</a>
|
||||
</div>
|
||||
<VirtualScroll
|
||||
data={list.items || []}
|
||||
totalCount={(list.items || []).length}
|
||||
style={{ height: '100%', width: '100%' }}
|
||||
itemContent={(i, item) => <ListItemEntry list={list} item={item} />}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const ListItemEntry = ({ list, item }) => (
|
||||
<div className="p-4 border-solid border-b cursor-pointer">
|
||||
<span className="text-md">{item.name}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={item.done}
|
||||
onChange={() => {
|
||||
setDone(list, item, !item.done);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
const Feed = ({ selected }) => {
|
||||
const selectedList = Store.useState(s => s.selectedList);
|
||||
|
||||
return (
|
||||
<Content visible={selected} className="p-4">
|
||||
<List className="h-full w-full">
|
||||
{selected && selectedList ? (
|
||||
<ListItems
|
||||
list={selectedList}
|
||||
onClose={() =>
|
||||
Store.update(s => {
|
||||
s.selectedList = null;
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<AllLists
|
||||
onSelect={list => {
|
||||
Store.update(s => {
|
||||
s.selectedList = list;
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</List>
|
||||
</Content>
|
||||
);
|
||||
};
|
||||
|
||||
export default Feed;
|
||||
Reference in New Issue
Block a user