Skip to content

Commit 43c94c7

Browse files
committed
fix input
1 parent d47f502 commit 43c94c7

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

app/components/Input.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { cn } from "@/lib/utils"
66
import { prepareArg } from "../utils"
77

88
interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
9-
value?: string
109
graph: Graph
1110
onValueChange: (node: PathNode) => void
1211
handleSubmit?: (node: any) => void
@@ -16,7 +15,7 @@ interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
1615
scrollToBottom?: () => void
1716
}
1817

19-
export default function Input({ value, onValueChange, handleSubmit, graph, icon, node, className, parentClassName, scrollToBottom, ...props }: Props) {
18+
export default function Input({ onValueChange, handleSubmit, graph, icon, node, className, parentClassName, scrollToBottom, ...props }: Props) {
2019

2120
const [open, setOpen] = useState(false)
2221
const [options, setOptions] = useState<any[]>([])
@@ -38,15 +37,15 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
3837
let isLastRequest = true
3938
const timeout = setTimeout(async () => {
4039

41-
if (!value || node?.id) {
42-
if (!value) {
40+
if (!node?.name) {
41+
if (!node?.name) {
4342
setOptions([])
4443
}
4544
setOpen(false)
4645
return
4746
}
4847

49-
const result = await fetch(`/api/repo/${prepareArg(graph.Id)}/?prefix=${prepareArg(value)}`, {
48+
const result = await fetch(`/api/repo/${prepareArg(graph.Id)}/?prefix=${prepareArg(node?.name)}`, {
5049
method: 'POST'
5150
})
5251

@@ -66,7 +65,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
6665

6766
setOptions(completions || [])
6867

69-
if (completions?.length > 0) {
68+
if (completions?.length > 0 && !node?.id) {
7069
setOpen(true)
7170
} else {
7271
setOpen(false)
@@ -77,7 +76,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
7776
clearTimeout(timeout)
7877
isLastRequest = false
7978
}
80-
}, [value, graph.Id])
79+
}, [node?.name, graph.Id])
8180

8281
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
8382
const container = containerRef.current
@@ -87,6 +86,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
8786
const option = options.find((o, i) => i === selectedOption)
8887
if (!option) return
8988
if (handleSubmit) {
89+
onValueChange({ name: option.properties.name, id: option.id })
9090
handleSubmit(option)
9191
} else {
9292
if (!open) return
@@ -144,7 +144,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
144144
}}
145145
onKeyDown={handleKeyDown}
146146
className={cn("w-full border p-2 rounded-md pointer-events-auto", className)}
147-
value={value || ""}
147+
value={node?.name || ""}
148148
onChange={(e) => {
149149
const newVal = e.target.value
150150
const invalidChars = /[%*()\-\[\]{};:"|~]/;

0 commit comments

Comments
 (0)