11import { FileTextIcon } from "@radix-ui/react-icons" ;
22import { Box , Card , Flex , Text , Tooltip } from "@radix-ui/themes" ;
33import type { TaskArtifact } from "@shared/types" ;
4+ import { useQuery } from "@tanstack/react-query" ;
45import { formatDistanceToNow } from "date-fns" ;
5- import { useEffect , useState } from "react" ;
66
77interface TaskArtifactsProps {
88 taskId : string ;
@@ -17,34 +17,21 @@ export function TaskArtifacts({
1717 selectedArtifact,
1818 onArtifactSelect,
1919} : TaskArtifactsProps ) {
20- const [ artifacts , setArtifacts ] = useState < TaskArtifact [ ] > ( [ ] ) ;
21-
22- useEffect ( ( ) => {
23- if ( ! repoPath || ! taskId ) return ;
24-
25- const loadArtifacts = async ( ) => {
26- try {
27- const files = await window . electronAPI ?. listTaskArtifacts (
28- repoPath ,
29- taskId ,
30- ) ;
31- if ( files ) {
32- setArtifacts ( files as TaskArtifact [ ] ) ;
33- }
34- } catch ( error ) {
35- console . error ( "Failed to load task artifacts:" , error ) ;
20+ const { data : artifacts = [ ] } = useQuery ( {
21+ queryKey : [ "task-artifacts" , repoPath , taskId ] ,
22+ enabled : ! ! repoPath && ! ! taskId ,
23+ refetchInterval : 5000 ,
24+ queryFn : async ( ) => {
25+ if ( ! window . electronAPI ) {
26+ throw new Error ( "Electron API unavailable" ) ;
3627 }
37- } ;
38-
39- loadArtifacts ( ) ;
40-
41- // Auto-refresh artifacts every 5 seconds
42- const interval = setInterval ( ( ) => {
43- loadArtifacts ( ) ;
44- } , 5000 ) ;
45-
46- return ( ) => clearInterval ( interval ) ;
47- } , [ repoPath , taskId ] ) ;
28+ const files = await window . electronAPI . listTaskArtifacts (
29+ repoPath as string ,
30+ taskId ,
31+ ) ;
32+ return ( files as TaskArtifact [ ] ) ?? [ ] ;
33+ } ,
34+ } ) ;
4835
4936 if ( ! repoPath || artifacts . length === 0 ) {
5037 return null ;
0 commit comments