Skip to content

Commit

Permalink
frontend: display errors on search page
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Dec 4, 2024
1 parent 22c4444 commit 86faf6f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions zettelkasten-front/src/pages/cards/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function SearchPage({
const [useClassicSearch, setUseClassicSearch] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [chunks, setChunks] = useState<CardChunk[]>([]);
const [error, setError] = useState<string>("");

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

Expand All @@ -39,11 +40,13 @@ export function SearchPage({

async function handleSearch(inputTerm = "") {
setIsLoading(true);
setError("")
setCards([]);
let term = inputTerm == "" ? searchTerm : inputTerm;

try {
if (useClassicSearch) {
setError("")
const data = await fetchCards(term);
if (data === null) {
setCards([]);
Expand All @@ -64,7 +67,7 @@ export function SearchPage({
}
} catch (error) {
console.error("Search error:", error);
// Handle error appropriately
setError(error);
} finally {
setIsLoading(false);
}
Expand Down Expand Up @@ -203,8 +206,16 @@ export function SearchPage({
</div>
</div>
) : (
<div className="flex justify-center w-full py-20">
Search returned no results
<div>
{error === "" ? (
<div className="flex justify-center w-full py-20">
Search returned no results
</div>
) : (
<div className="flex justify-center w-full py-20">
Search returned an error: {error.message}
</div>
)}
</div>
)}
</div>
Expand Down

0 comments on commit 86faf6f

Please sign in to comment.