Skip to content

Commit

Permalink
frontend: re-enable classic search
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Oct 5, 2024
1 parent 2333e94 commit 682bdb4
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions zettelkasten-front/src/pages/cards/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function SearchPage({
const [currentPage, setCurrentPage] = useState(1);
const [itemsPerPage, setItemsPerPage] = useState(20);
const { partialCards } = usePartialCardContext();
const [useClassicSearch, setUseClassicSearch] = useState<boolean>(true);

const [tags, setTags] = useState<Tag[]>([]);

Expand All @@ -36,13 +37,23 @@ export function SearchPage({
function handleSearch(inputTerm = "") {
let term = inputTerm == "" ? searchTerm : inputTerm;

semanticSearchCards(term).then((data) => {
if (data === null) {
setCards([]);
} else {
setCards(data);
}
});
if (useClassicSearch) {
fetchCards(term).then((data) => {
if (data === null) {
setCards([]);
} else {
setCards(data);
}
});
} else {
semanticSearchCards(term).then((data) => {
if (data === null) {
setCards([]);
} else {
setCards(data);
}
});
}
}

function handleSortChange(e: ChangeEvent<HTMLSelectElement>) {
Expand Down Expand Up @@ -79,13 +90,17 @@ export function SearchPage({
handleSearch(term);
} else {
fetchTags();
handleSearch();
handleSearch();
}
document.title = "Zettelgarden - Search";
}, []);

const currentItems = getSortedAndPagedCards();

const handleCheckboxChange = (event) => {
setUseClassicSearch(event.target.checked);
};

return (
<div>
<div>
Expand Down Expand Up @@ -116,6 +131,14 @@ export function SearchPage({
tags={tags.filter((tag) => tag.card_count > 0)}
handleTagClick={handleTagClick}
/>
<label>
<input
type="checkbox"
checked={useClassicSearch}
onChange={handleCheckboxChange}
/>
Use Classic Search
</label>
</div>
</div>
{currentItems.length > 0 ? (
Expand Down

0 comments on commit 682bdb4

Please sign in to comment.