11import { MagnifyingGlassIcon , XMarkIcon } from "@heroicons/react/20/solid" ;
22import { useNavigate } from "@remix-run/react" ;
33import { useCallback , useEffect , useRef , useState } from "react" ;
4- import { AISparkleIcon } from "~/assets/icons/AISparkleIcon" ;
54import { Input } from "~/components/primitives/Input" ;
65import { ShortcutKey } from "~/components/primitives/ShortcutKey" ;
76import { cn } from "~/utils/cn" ;
87import { useOptimisticLocation } from "~/hooks/useOptimisticLocation" ;
9- import { AIFilterInput } from "~/components/runs/v3/AIFilterInput" ;
10-
11- type SearchMode = "ai" | "text" ;
128
139export function LogsSearchInput ( ) {
1410 const location = useOptimisticLocation ( ) ;
@@ -19,7 +15,6 @@ export function LogsSearchInput() {
1915 const searchParams = new URLSearchParams ( location . search ) ;
2016 const initialSearch = searchParams . get ( "search" ) ?? "" ;
2117
22- const [ mode , setMode ] = useState < SearchMode > ( "text" ) ;
2318 const [ text , setText ] = useState ( initialSearch ) ;
2419 const [ isFocused , setIsFocused ] = useState ( false ) ;
2520
@@ -54,81 +49,47 @@ export function LogsSearchInput() {
5449 navigate ( `${ location . pathname } ?${ params . toString ( ) } ` , { replace : true } ) ;
5550 } , [ location . pathname , location . search , navigate ] ) ;
5651
57- const toggleMode = useCallback ( ( ) => {
58- // Clear text search when switching modes
59- if ( mode === "text" && text . trim ( ) ) {
60- handleClear ( ) ;
61- }
62- setMode ( ( prev ) => ( prev === "ai" ? "text" : "ai" ) ) ;
63- } , [ mode , text , handleClear ] ) ;
64-
6552 return (
6653 < div className = "flex items-center gap-1" >
67- { /* Mode toggle button */ }
68- < button
69- type = "button"
70- onClick = { toggleMode }
71- className = { cn (
72- "flex size-6 items-center justify-center rounded border transition-colors" ,
73- mode === "ai"
74- ? "border-indigo-500/50 bg-indigo-500/10 text-indigo-400 hover:bg-indigo-500/20"
75- : "border-charcoal-700 bg-charcoal-750 text-text-dimmed hover:bg-charcoal-700 hover:text-text-bright"
76- ) }
77- title = { mode === "ai" ? "Switch to text search" : "Switch to AI search" }
78- >
79- { mode === "ai" ? (
80- < AISparkleIcon className = "size-3.5" />
81- ) : (
82- < MagnifyingGlassIcon className = "size-3.5" />
83- ) }
84- </ button >
85-
86- { /* Show AI or text search based on mode */ }
87- { mode === "ai" ? (
88- < AIFilterInput />
89- ) : (
90- < div className = "flex items-center gap-1" >
91- < div className = "relative h-6 min-w-52" >
92- < Input
93- type = "text"
94- ref = { inputRef }
95- variant = "secondary-small"
96- placeholder = "Search messages…"
97- value = { text }
98- onChange = { ( e ) => setText ( e . target . value ) }
99- fullWidth
100- className = { cn ( isFocused && "placeholder:text-text-dimmed/70" ) }
101- onKeyDown = { ( e ) => {
102- if ( e . key === "Enter" ) {
103- e . preventDefault ( ) ;
104- handleSubmit ( ) ;
105- }
106- if ( e . key === "Escape" ) {
107- e . currentTarget . blur ( ) ;
108- }
109- } }
110- onFocus = { ( ) => setIsFocused ( true ) }
111- onBlur = { ( ) => setIsFocused ( false ) }
112- icon = { < MagnifyingGlassIcon className = "size-4" /> }
113- accessory = {
114- text . length > 0 ? (
115- < ShortcutKey shortcut = { { key : "enter" } } variant = "small" />
116- ) : undefined
117- }
118- />
119- </ div >
54+ < div className = "relative h-6 min-w-52" >
55+ < Input
56+ type = "text"
57+ ref = { inputRef }
58+ variant = "secondary-small"
59+ placeholder = "Search logs…"
60+ value = { text }
61+ onChange = { ( e ) => setText ( e . target . value ) }
62+ fullWidth
63+ className = { cn ( isFocused && "placeholder:text-text-dimmed/70" ) }
64+ onKeyDown = { ( e ) => {
65+ if ( e . key === "Enter" ) {
66+ e . preventDefault ( ) ;
67+ handleSubmit ( ) ;
68+ }
69+ if ( e . key === "Escape" ) {
70+ e . currentTarget . blur ( ) ;
71+ }
72+ } }
73+ onFocus = { ( ) => setIsFocused ( true ) }
74+ onBlur = { ( ) => setIsFocused ( false ) }
75+ icon = { < MagnifyingGlassIcon className = "size-4" /> }
76+ accessory = {
77+ text . length > 0 ? (
78+ < ShortcutKey shortcut = { { key : "enter" } } variant = "small" />
79+ ) : undefined
80+ }
81+ />
82+ </ div >
12083
121- { text . length > 0 && (
122- < button
123- type = "button"
124- onClick = { handleClear }
125- className = "flex size-6 items-center justify-center rounded text-text-dimmed hover:bg-charcoal-700 hover:text-text-bright"
126- title = "Clear search"
127- >
128- < XMarkIcon className = "size-4" />
129- </ button >
130- ) }
131- </ div >
84+ { text . length > 0 && (
85+ < button
86+ type = "button"
87+ onClick = { handleClear }
88+ className = "flex size-6 items-center justify-center rounded text-text-dimmed hover:bg-charcoal-700 hover:text-text-bright"
89+ title = "Clear search"
90+ >
91+ < XMarkIcon className = "size-4" />
92+ </ button >
13293 ) }
13394 </ div >
13495 ) ;
0 commit comments