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

Commit

Permalink
fix(hero.tsx): get reccomandation timeout causes white page
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanjpg committed Jan 5, 2024
1 parent f478a01 commit a468e18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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 searchNormal from "../assets/searchNormal.svg";
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 Hero = () => {
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
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 @@ const Hero = () => {
useDidUpdate(async () => {
const results = await fetchRecommendations("stars", 3, null, searchTerm);

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

return (
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;
}

0 comments on commit a468e18

Please sign in to comment.