feat: Add directory tree tab to session files

This commit is contained in:
weishu
2026-02-06 20:18:46 +08:00
parent dc7472f1d0
commit fb9abc18d4
13 changed files with 573 additions and 32 deletions
@@ -0,0 +1,49 @@
import { useQuery } from '@tanstack/react-query'
import type { ApiClient } from '@/api/client'
import type { DirectoryEntry } from '@/types/api'
import { queryKeys } from '@/lib/query-keys'
export function useSessionDirectory(
api: ApiClient | null,
sessionId: string | null,
path: string,
options?: { enabled?: boolean }
): {
entries: DirectoryEntry[]
error: string | null
isLoading: boolean
refetch: () => Promise<unknown>
} {
const resolvedSessionId = sessionId ?? 'unknown'
const enabled = Boolean(api && sessionId) && (options?.enabled ?? true)
const query = useQuery({
queryKey: queryKeys.sessionDirectory(resolvedSessionId, path),
queryFn: async () => {
if (!api || !sessionId) {
throw new Error('Session unavailable')
}
const response = await api.listSessionDirectory(sessionId, path)
if (!response.success) {
return { entries: [], error: response.error ?? 'Failed to list directory' }
}
return { entries: response.entries ?? [], error: null }
},
enabled,
})
const queryError = query.error instanceof Error
? query.error.message
: query.error
? 'Failed to list directory'
: null
return {
entries: query.data?.entries ?? [],
error: queryError ?? query.data?.error ?? null,
isLoading: query.isLoading,
refetch: query.refetch
}
}
+9 -2
View File
@@ -5,6 +5,7 @@ export function useAppGoBack(): () => void {
const navigate = useNavigate()
const router = useRouter()
const pathname = useLocation({ select: (location) => location.pathname })
const search = useLocation({ select: (location) => location.search })
return useCallback(() => {
// Use explicit path navigation for consistent behavior across all environments
@@ -22,7 +23,13 @@ export function useAppGoBack(): () => void {
// For single file view, go back to files list
if (pathname.match(/^\/sessions\/[^/]+\/file$/)) {
const filesPath = pathname.replace(/\/file$/, '/files')
navigate({ to: filesPath })
const tab = (search && typeof search === 'object' && 'tab' in search)
? (search as { tab?: unknown }).tab
: undefined
const nextSearch = tab === 'directories' ? { tab: 'directories' as const } : {}
navigate({ to: filesPath, search: nextSearch })
return
}
@@ -35,5 +42,5 @@ export function useAppGoBack(): () => void {
// Fallback to history.back() for other cases
router.history.back()
}, [navigate, pathname, router])
}, [navigate, pathname, router, search])
}