(props: FilesPanelProps)
| 13 | } |
| 14 | |
| 15 | export function FilesPanel(props: FilesPanelProps): ReactElement { |
| 16 | const [path, setPath] = useState(''); |
| 17 | const [listing, setListing] = useState<DirListing | null>(null); |
| 18 | const [error, setError] = useState<string | null>(null); |
| 19 | const openOrFocus = useWorkspace((s) => s.openOrFocus); |
| 20 | |
| 21 | useEffect(() => { |
| 22 | let alive = true; |
| 23 | setListing(null); |
| 24 | setError(null); |
| 25 | |
| 26 | const refresh = async (): Promise<void> => { |
| 27 | try { |
| 28 | const data = await listFiles(props.wsId, path); |
| 29 | if (!alive) return; |
| 30 | setListing(data); |
| 31 | setError(null); |
| 32 | } catch (err) { |
| 33 | if (!alive) return; |
| 34 | setError((err as Error).message); |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | void refresh(); |
| 39 | const id = setInterval(() => void refresh(), POLL_MS); |
| 40 | return () => { |
| 41 | alive = false; |
| 42 | clearInterval(id); |
| 43 | }; |
| 44 | }, [props.wsId, path]); |
| 45 | |
| 46 | // Reset path when switching workspaces. |
| 47 | useEffect(() => { |
| 48 | setPath(''); |
| 49 | }, [props.wsId]); |
| 50 | |
| 51 | const enter = (entry: FileEntry): void => { |
| 52 | if (entry.kind === 'dir' || entry.kind === 'symlink') { |
| 53 | setPath(path ? `${path}/${entry.name}` : entry.name); |
| 54 | return; |
| 55 | } |
| 56 | if (entry.kind === 'file') { |
| 57 | // Open the file in the dedicated viewer tab (VS Code-style). |
| 58 | const rel = path ? `${path}/${entry.name}` : entry.name; |
| 59 | openOrFocus({ kind: 'file-viewer', params: { wsId: props.wsId, path: rel } }); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | const breadcrumb = path.split('/').filter(Boolean); |
| 64 | |
| 65 | return ( |
| 66 | <section className="panel files-panel"> |
| 67 | <header className="panel-header"> |
| 68 | <span className="panel-title">files</span> |
| 69 | <nav className="files-breadcrumb"> |
| 70 | <button |
| 71 | type="button" |
| 72 | className="files-crumb" |
nothing calls this directly
no test coverage detected