Skip to content

Commit dafc549

Browse files
gkorlandCopilot
andcommitted
fix(combobox): add error handling and fix placeholder selection
- Add catch block for network errors with toast notification - Disable Select during loading and when no options available - Use placeholder prop instead of selectable placeholder items - Move lastFetch timestamp update to after successful fetch Addresses CodeRabbit review comments on combobox.tsx. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 78780de commit dafc549

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

app/src/components/combobox.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export default function Combobox({ options, setOptions, selectedValue, onSelecte
4343

4444
const json = await result.json()
4545
setOptions(json.repositories)
46+
setLastFetch(Date.now())
47+
} catch (error) {
48+
toast({
49+
variant: "destructive",
50+
title: "Uh oh! Something went wrong.",
51+
description: error instanceof Error ? error.message : "Failed to fetch repositories.",
52+
})
4653
} finally {
4754
setIsFetchingOptions(false)
4855
}
@@ -60,16 +67,14 @@ export default function Combobox({ options, setOptions, selectedValue, onSelecte
6067

6168
//check if last fetch was less than 30 seconds ago
6269
if (lastFetch && now - lastFetch < 30000) return;
63-
64-
setLastFetch(now);
65-
70+
6671
fetchOptions()
6772
}, [open])
6873

6974
return (
70-
<Select open={open} onOpenChange={setOpen} disabled={options.length === 0 && !isFetchingOptions} value={isFetchingOptions ? "Fetching options..." : options.length !== 0 ? selectedValue : "No options found"} onValueChange={onSelectedValue}>
75+
<Select open={open} onOpenChange={setOpen} disabled={isFetchingOptions || (options.length === 0)} value={selectedValue} onValueChange={onSelectedValue}>
7176
<SelectTrigger className="z-10 md:z-0 rounded-md border border-border focus:ring-1 focus:ring-primary">
72-
<SelectValue placeholder="Select a repo" />
77+
<SelectValue placeholder={isFetchingOptions ? "Fetching options..." : "Select a repo"} />
7378
</SelectTrigger>
7479
<SelectContent>
7580
{

0 commit comments

Comments
 (0)