diff --git a/src/renderer/components/Sidebar.tsx b/src/renderer/components/Sidebar.tsx index 2417e4d..f5ba6e8 100644 --- a/src/renderer/components/Sidebar.tsx +++ b/src/renderer/components/Sidebar.tsx @@ -2,7 +2,6 @@ import { Fragment, useMemo, useState } from 'react'; import { GoFile, GoGear, - GoItalic, GoPencil, GoPlusCircle, GoSearch, @@ -26,8 +25,6 @@ export default function Sidebar() { const [showPreferencesModal, setShowPreferencesModal] = useState(false); const [showTagsModal, setShowTagsModal] = useState(false); - const [searchBy, setSearchBy] = useState('name'); - const { tags } = useTags(); const { notes, handleCreateNewNote } = useNotes(); const { handleChangeDir } = useDir(); @@ -37,28 +34,25 @@ export default function Sidebar() { return []; } - return notes.filter((fileName) => { - const allSearchTags = searchQuery - .split(',') - .map((item) => item.trim()) - .filter((item) => item.length > 0); - - if (searchBy === 'name') { - //@ts-ignore - - return fileName.toLowerCase().includes(searchQuery.toLowerCase()); - } else if (allSearchTags.length > 0 && searchBy === 'tag') { - const thisNoteTags = Object.entries(tags).filter( - //@ts-ignore - (tag) => tag[1][fileName] === true, - ); - - return thisNoteTags.some((tag) => allSearchTags.includes(tag[0])); - } else { - return true; - } + return notes.filter((noteName) => { + const allQueries = searchQuery.split(',').map((item) => item.trim()); + + // if it has multiple queries, all needs to match aka all or nothing + + const thisNoteTags = Object.entries(tags) + .filter((tag) => tag[1][noteName] === true) + .map((tg) => tg[0]); + + return allQueries.every((query) => { + if (query.startsWith('#')) { + const tagToMatch = query.slice(1); + return thisNoteTags.some((tag) => tag === tagToMatch); + } else { + return noteName.toLowerCase().includes(query.toLowerCase()); + } + }); }); - }, [searchQuery, notes, searchBy]); + }, [searchQuery, notes]); return ( @@ -85,38 +79,12 @@ export default function Sidebar() { size={13} /> setSearchQuery(e.target.value)} /> - - {searchBy === 'name' ? ( - setSearchBy('tag')} - className="absolute top-2 right-2" - size={13} - /> - ) : ( - setSearchBy('name')} - className="absolute top-2 right-2" - size={13} - /> - )} - - {/*
- - - -
*/}