Skip to content

Commit

Permalink
Add basic search
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 9, 2024
1 parent 81eacde commit 8e93e79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ export default function Frame({ selectedFolderURL, setSelectedFolderURL }) {
initial={animation}
animate={animation}
transition={{ ease: 'anticipate', duration: 0.2 }}
style={{
borderLeft: '1px solid #e0e0e0',
}}
style={{ borderLeft: '1px solid #e0e0e0' }}
>
<div id="select" className="components-accessible-toolbar">
<ToolbarGroup className="components-toolbar-group">
Expand All @@ -127,9 +125,7 @@ export default function Frame({ selectedFolderURL, setSelectedFolderURL }) {
const newItem = { id: uuidv4() };
setItems([newItem, ...items]);
setCurrentId(newItem.id);
setItem(currentId, {
blocks: null,
});
setItem(currentId, { blocks: null });
}}
/>
</ToolbarGroup>
Expand Down
15 changes: 11 additions & 4 deletions src/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
type: 'list',
search: '',
filters: [],
page: 1,
perPage: 5,
sort: {
field: 'path',
direction: 'desc',
Expand All @@ -27,6 +25,12 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
layout: {},
});

if (view.search) {
items = items.filter(({ path }) =>
path.toLowerCase().includes(view.search.toLowerCase())
);
}

return (
<DataViews
data={items}
Expand All @@ -37,6 +41,7 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
// To do: remove hidden text from rows.
header: ' ',
enableHiding: false,
enableSorting: false,
render({ item }) {
return <Title item={item} />;
},
Expand All @@ -48,8 +53,10 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
totalPages: 1,
}}
onSelectionChange={([item]) => {
setCurrentId(item.id);
setItem(currentId, { blocks: null });
if (item) {
setCurrentId(item.id);
setItem(currentId, { blocks: null });
}
}}
supportedLayouts={['list']}
/>
Expand Down

0 comments on commit 8e93e79

Please sign in to comment.