fix: update backend response for /list route (#186)

* update structure of list directory response

* fmt
This commit is contained in:
Gabriel Gordon-Hall
2025-07-15 11:38:13 +01:00
committed by GitHub
parent ed781b552a
commit d994622a99
2 changed files with 22 additions and 3 deletions

View File

@@ -66,7 +66,14 @@ export function FolderPicker({
try {
const result = await fileSystemApi.list(path);
setEntries(result.entries || []);
// Ensure result exists and has the expected structure
if (!result || typeof result !== 'object') {
throw new Error('Invalid response from file system API');
}
// Safely access entries, ensuring it's an array
const entries = Array.isArray(result.entries) ? result.entries : [];
setEntries(entries);
const newPath = result.current_path || '';
setCurrentPath(newPath);
// Update manual path if we have a specific path (not for initial home directory load)
@@ -75,6 +82,8 @@ export function FolderPicker({
}
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load directory');
// Reset entries to empty array on error
setEntries([]);
} finally {
setLoading(false);
}