1- import { useFetcher } from "@remix-run/react" ;
2- import { useState , useEffect } from "react" ;
1+ import { useFetcher , useNavigate } from "@remix-run/react" ;
2+ import { useEffect , useState } from "react" ;
33import { AISparkleIcon } from "~/assets/icons/AISparkleIcon" ;
4- import { Button } from "~/components/primitives/Buttons" ;
54import { Input } from "~/components/primitives/Input" ;
5+ import { ShortcutKey } from "~/components/primitives/ShortcutKey" ;
66import { Spinner } from "~/components/primitives/Spinner" ;
7- import { useSearchParams } from "~/hooks/useSearchParam " ;
7+ import { useEnvironment } from "~/hooks/useEnvironment " ;
88import { useOrganization } from "~/hooks/useOrganizations" ;
99import { useProject } from "~/hooks/useProject" ;
10- import { useEnvironment } from "~/hooks/useEnvironment" ;
11- import { type TaskRunListSearchFilters } from "./RunFilters" ;
10+ import { useSearchParams } from "~/hooks/useSearchParam" ;
1211import { objectToSearchParams } from "~/utils/searchParams" ;
13- import { ShortcutKey } from "~/components/primitives/ShortcutKey " ;
12+ import { type TaskRunListSearchFilters } from "./RunFilters " ;
1413
1514type AIFilterResult =
1615 | {
@@ -26,32 +25,37 @@ type AIFilterResult =
2625
2726export function AIFilterInput ( ) {
2827 const [ text , setText ] = useState ( "" ) ;
29- const { replace } = useSearchParams ( ) ;
28+ const navigate = useNavigate ( ) ;
3029 const organization = useOrganization ( ) ;
3130 const project = useProject ( ) ;
3231 const environment = useEnvironment ( ) ;
3332
3433 const fetcher = useFetcher < AIFilterResult > ( ) ;
3534
3635 useEffect ( ( ) => {
37- if ( fetcher . data ?. success ) {
36+ if ( fetcher . data ?. success && fetcher . state === "loading" ) {
37+ // Clear the input after successful application
38+ setText ( "" ) ;
39+
3840 const searchParams = objectToSearchParams ( fetcher . data . filters ) ;
3941 if ( ! searchParams ) {
4042 return ;
4143 }
4244
43- replace ( searchParams ) ;
45+ console . log ( "AI filter success" , {
46+ data : fetcher . data ,
47+ searchParams : searchParams . toString ( ) ,
48+ } ) ;
4449
45- // Clear the input after successful application
46- setText ( "" ) ;
50+ navigate ( `${ location . pathname } ?${ searchParams . toString ( ) } ` , { replace : true } ) ;
4751
4852 // TODO: Show success message with explanation
4953 console . log ( `AI applied filters: ${ fetcher . data . explanation } ` ) ;
5054 } else if ( fetcher . data ?. success === false ) {
5155 // TODO: Show error with suggestions
5256 console . error ( fetcher . data . error , fetcher . data . suggestions ) ;
5357 }
54- } , [ fetcher . data , replace ] ) ;
58+ } , [ fetcher . data , navigate ] ) ;
5559
5660 const isLoading = fetcher . state === "submitting" ;
5761
0 commit comments