Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

fix: Search results that take too long no longer generate a white error page #503

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cmdKIcon from "../assets/cmdK.svg";
import SearchedRepoCard from "./SearchedRepoCard";
import { Combobox } from "@headlessui/react";
import { ToastTrigger } from "../lib/reactHotToast";

const Hero = () => {
const containerRef = useRef<Document>(document);
Expand All @@ -17,14 +18,22 @@
const [comboBoxSelection, setComboBoxSelection] = useState("");
const [hasFocus, setFocus] = useState(false);

const setFetchedDataWithCatch = (results: DbRepo[] | null) => {
if (results) {
setFetchedData(results);
} else {
ToastTrigger({ message: "Failed to fetch recommendations", type: "error" });
}
};

Check failure on line 28 in src/components/Hero.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Trailing spaces not allowed

Check failure on line 28 in src/components/Hero.tsx

View workflow job for this annotation

GitHub Actions / Code standards

Trailing spaces not allowed
const handleCmdK = async (e: KeyboardEvent) => {
comboButtonRef.current?.click();
if (!hasFocus) {
searchBoxRef.current?.focus();
setFocus(true);
const results = await fetchRecommendations("stars", 3, null, searchTerm);

setFetchedData(results);
setFetchedDataWithCatch(results);
} else {
searchBoxRef.current?.blur();
setFocus(false);
Expand All @@ -49,7 +58,7 @@
useDidUpdate(async () => {
const results = await fetchRecommendations("stars", 3, null, searchTerm);

setFetchedData(results);
setFetchedDataWithCatch(results);
}, [searchTerm]);

return (
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useVotedRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
if (user) {
const data = await fetchRecommendations("myVotes", 1000, user, "");

if(!data) {

Check failure on line 16 in src/hooks/useVotedRepos.ts

View workflow job for this annotation

GitHub Actions / Code standards

Expected space(s) after "if"

Check failure on line 16 in src/hooks/useVotedRepos.ts

View workflow job for this annotation

GitHub Actions / Code standards

Expected space(s) after "if"
return setVotedReposIds([]);
}

return setVotedReposIds(data.map(({ id }) => id));
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ export async function fetchRecommendations (

error && console.error(error);

return recommendations as DbRepo[];
return recommendations as DbRepo[] | null;
}
Loading