11import { toast } from "@/components/ui/use-toast"
22import { getCategoryColorName , getCategoryColorValue , Graph } from "./model"
33import { useEffect , useRef , useState } from "react"
4- import { PathNode } from "../page "
4+ import { PathNode } from "@/lib/utils "
55import { cn } from "@/lib/utils"
66import { prepareArg } from "../utils"
77
88interface 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,13 @@ 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 ) {
43- setOptions ( [ ] )
44- }
40+ if ( ! node ?. name ) {
41+ setOptions ( [ ] )
4542 setOpen ( false )
4643 return
4744 }
4845
49- const result = await fetch ( `/api/repo/${ prepareArg ( graph . Id ) } /?prefix=${ prepareArg ( value ) } ` , {
46+ const result = await fetch ( `/api/repo/${ prepareArg ( graph . Id ) } /?prefix=${ prepareArg ( node ?. name ) } ` , {
5047 method : 'POST'
5148 } )
5249
@@ -66,7 +63,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
6663
6764 setOptions ( completions || [ ] )
6865
69- if ( completions ?. length > 0 ) {
66+ if ( completions ?. length > 0 && ! node ?. id ) {
7067 setOpen ( true )
7168 } else {
7269 setOpen ( false )
@@ -77,7 +74,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
7774 clearTimeout ( timeout )
7875 isLastRequest = false
7976 }
80- } , [ value , graph . Id ] )
77+ } , [ node ?. name , graph . Id ] )
8178
8279 const handleKeyDown = ( e : React . KeyboardEvent < HTMLInputElement > ) => {
8380 const container = containerRef . current
@@ -87,6 +84,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
8784 const option = options . find ( ( o , i ) => i === selectedOption )
8885 if ( ! option ) return
8986 if ( handleSubmit ) {
87+ onValueChange ( { name : option . properties . name , id : option . id } )
9088 handleSubmit ( option )
9189 } else {
9290 if ( ! open ) return
@@ -133,7 +131,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
133131
134132 return (
135133 < div
136- className = { cn ( "w-[20dvw] relative pointer-events-none rounded-md gap-4" , parentClassName ) }
134+ className = { cn ( "w-full md:w- [20dvw] relative pointer-events-none rounded-md gap-4" , parentClassName ) }
137135 data-name = 'search-bar'
138136 >
139137 < input
@@ -144,7 +142,8 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
144142 } }
145143 onKeyDown = { handleKeyDown }
146144 className = { cn ( "w-full border p-2 rounded-md pointer-events-auto" , className ) }
147- value = { value || "" }
145+ placeholder = "Search for nodes in the graph"
146+ value = { node ?. name || "" }
148147 onChange = { ( e ) => {
149148 const newVal = e . target . value
150149 const invalidChars = / [ % * ( ) \- \[ \] { } ; : " | ~ ] / ;
@@ -168,7 +167,7 @@ export default function Input({ value, onValueChange, handleSubmit, graph, icon,
168167 open &&
169168 < div
170169 ref = { containerRef }
171- className = "z-10 w-full bg-white absolute flex flex-col pointer-events-auto border rounded-md max-h-[50dvh] overflow-y-auto overflow-x-hidden p-2 gap-2"
170+ className = "z-10 w-full bg-white absolute flex flex-col pointer-events-auto border rounded-md md: max-h-[50dvh] h-[25dvh ] overflow-y-auto overflow-x-hidden p-2 gap-2"
172171 data-name = 'search-bar-list'
173172 style = { {
174173 top : inputHeight + 16
0 commit comments