Skip to content

Commit 00a2a72

Browse files
authored
Merge branch 'staging' into fix-search-element
2 parents 9064564 + 6cd1130 commit 00a2a72

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

app/components/code-graph.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface Props {
2121
onFetchGraph: (graphName: string) => void,
2222
onFetchNode: (nodeIds: string[]) => Promise<any[]>,
2323
options: string[]
24+
setOptions: Dispatch<SetStateAction<string[]>>
2425
isShowPath: boolean
2526
setPath: Dispatch<SetStateAction<Path | undefined>>
2627
chartRef: MutableRefObject<cytoscape.Core | null>
@@ -119,6 +120,7 @@ export function CodeGraph({
119120
onFetchGraph,
120121
onFetchNode,
121122
options,
123+
setOptions,
122124
isShowPath,
123125
setPath,
124126
chartRef,
@@ -397,6 +399,7 @@ export function CodeGraph({
397399
<header className="flex flex-col gap-4">
398400
<Combobox
399401
options={options}
402+
setOptions={setOptions}
400403
selectedValue={graphName}
401404
onSelectedValue={handleSelectedValue}
402405
/>

app/components/combobox.tsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
11
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
2+
import { toast } from "@/components/ui/use-toast";
3+
import { useEffect, useState } from "react";
24

35
interface Props {
46
options: string[]
7+
setOptions: (options: string[]) => void
58
selectedValue: string
69
onSelectedValue: (value: string) => void
710

811
}
912

10-
export default function Combobox({ options, selectedValue, onSelectedValue }: Props) {
13+
export default function Combobox({ options, setOptions, selectedValue, onSelectedValue }: Props) {
14+
15+
const [open, setOpen] = useState(false)
16+
const [lastOpened, setLastOpened] = useState<number>();
17+
18+
const fetchOptions = async () => {
19+
const result = await fetch(`/api/repo`, {
20+
method: 'GET',
21+
})
22+
23+
if (!result.ok) {
24+
toast({
25+
variant: "destructive",
26+
title: "Uh oh! Something went wrong.",
27+
description: await result.text(),
28+
})
29+
return
30+
}
31+
32+
const json = await result.json()
33+
setOptions(json.result)
34+
}
35+
36+
useEffect(() => {
37+
fetchOptions()
38+
}, [])
39+
40+
useEffect(() => {
41+
if (!open) return
42+
43+
const now = Date.now();
44+
45+
if (lastOpened && now - lastOpened < 30000) return;
46+
47+
setLastOpened(now);
48+
49+
fetchOptions()
50+
}, [open])
51+
1152
return (
12-
<Select value={selectedValue} onValueChange={onSelectedValue}>
53+
<Select open={open} onOpenChange={setOpen} value={selectedValue} onValueChange={onSelectedValue}>
1354
<SelectTrigger className="rounded-md border focus:ring-0 focus:ring-offset-0">
1455
<SelectValue placeholder="Select a repo" />
1556
</SelectTrigger>

app/page.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,6 @@ export default function Home() {
6565
const [isSubmit, setIsSubmit] = useState<boolean>(false);
6666
const chartRef = useRef<cytoscape.Core | null>(null)
6767

68-
useEffect(() => {
69-
const run = async () => {
70-
const result = await fetch(`/api/repo`, {
71-
method: 'GET',
72-
})
73-
74-
if (!result.ok) {
75-
toast({
76-
variant: "destructive",
77-
title: "Uh oh! Something went wrong.",
78-
description: await result.text(),
79-
})
80-
return
81-
}
82-
83-
const json = await result.json()
84-
setOptions(json.result)
85-
}
86-
87-
run()
88-
}, [])
89-
9068
async function onCreateRepo(e: React.FormEvent<HTMLFormElement>) {
9169
e.preventDefault()
9270

@@ -279,6 +257,7 @@ export default function Home() {
279257
<CodeGraph
280258
chartRef={chartRef}
281259
options={options}
260+
setOptions={setOptions}
282261
onFetchGraph={onFetchGraph}
283262
onFetchNode={onFetchNode}
284263
setPath={setPath}

0 commit comments

Comments
 (0)