import { useState } from 'react'; import { useQueryClient } from '@tanstack/react-query'; import { reposApi } from '../../lib/api/repos'; import { toast } from 'sonner'; interface FileTreeHeaderProps { owner: string; repo: string; } export function FileTreeHeader({ owner, repo }: FileTreeHeaderProps) { const [isRefreshing, setIsRefreshing] = useState(false); const queryClient = useQueryClient(); const handleRefresh = async () => { setIsRefreshing(true); try { // Invalidate backend cache const result = await reposApi.invalidateCache(owner, repo); // Invalidate React Query cache await queryClient.invalidateQueries({ queryKey: ['files', owner, repo], refetchType: 'all', // Force refetch even for inactive queries }); toast.success(`Cache cleared! ${result.invalidated_count} entries invalidated.`); } catch (error) { console.error('Failed to refresh cache:', error); toast.error('Failed to refresh cache. Please try again.'); } finally { setIsRefreshing(false); } }; return (