Parallel subagent pass: four typescript-pro agents on non-overlapping scopes.
Patterns applied:
- catch (err: any) { ... err.message ... } → catch (err) { ... getErrorMessage(err) ... }
using the new @fusion/core helper. Bare catch {} where the error was unused.
- SQLite row types: defined typed XxxRow interfaces per table and cast
.all()/.get() results via `as unknown as XxxRow[]` (the double cast is
required because better-sqlite3 returns Record<string, SQLOutputValue>).
- rowToX(row: any) converters: typed argument with the matching row interface.
- Dynamic settings key writes: (settings as Record<string, unknown>)[key].
- React event handlers and setState callbacks: inferred types or concrete
React.{Mouse,Change,Form}Event<...> where needed.
- pi-claude-cli: local PiMessage / PiContext duck types to avoid re-typing
pi-ai concrete shapes; typed Claude stream event message fields.
72 files changed, ~400 anys eliminated. Typecheck passes across the workspace.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import { useState, useEffect, useCallback } from "react";
|
|
import { getErrorMessage } from "@fusion/core";
|
|
import type { FileNode, FileListResponse } from "../api";
|
|
import { fetchFileList } from "../api";
|
|
|
|
interface UseFileBrowserReturn {
|
|
entries: FileNode[];
|
|
currentPath: string;
|
|
setPath: (path: string) => void;
|
|
loading: boolean;
|
|
error: string | null;
|
|
refresh: () => void;
|
|
}
|
|
|
|
/**
|
|
* Hook for browsing files in a task directory.
|
|
*
|
|
* @param taskId - The task ID to browse
|
|
* @param enabled - Whether to enable fetching (e.g., when tab is active)
|
|
* @param projectId - Optional project ID for scoped store resolution
|
|
* @returns File browser state and controls
|
|
*/
|
|
export function useFileBrowser(taskId: string, enabled: boolean, projectId?: string): UseFileBrowserReturn {
|
|
const [entries, setEntries] = useState<FileNode[]>([]);
|
|
const [currentPath, setCurrentPath] = useState<string>(".");
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
|
|
const refresh = useCallback(() => {
|
|
setRefreshKey((k) => k + 1);
|
|
}, []);
|
|
|
|
const setPath = useCallback((path: string) => {
|
|
setCurrentPath(path);
|
|
setError(null);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!enabled || !taskId) {
|
|
return;
|
|
}
|
|
|
|
let cancelled = false;
|
|
|
|
async function loadFiles() {
|
|
setLoading(true);
|
|
setError(null);
|
|
|
|
try {
|
|
const response: FileListResponse = await fetchFileList(
|
|
taskId,
|
|
currentPath === "." ? undefined : currentPath,
|
|
projectId
|
|
);
|
|
|
|
if (!cancelled) {
|
|
setEntries(response.entries);
|
|
}
|
|
} catch (err) {
|
|
if (!cancelled) {
|
|
setError(getErrorMessage(err) || "Failed to load files");
|
|
setEntries([]);
|
|
}
|
|
} finally {
|
|
if (!cancelled) {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
loadFiles();
|
|
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [taskId, currentPath, enabled, refreshKey, projectId]);
|
|
|
|
return {
|
|
entries,
|
|
currentPath,
|
|
setPath,
|
|
loading,
|
|
error,
|
|
refresh,
|
|
};
|
|
}
|