Skip to content

Commit

Permalink
Merge pull request #31 from sotopia-lab/fix_files
Browse files Browse the repository at this point in the history
Fix: Preserve File Contents During File System Refresh
  • Loading branch information
akhatua2 authored Jan 17, 2025
2 parents 1c96234 + 36c1d88 commit 671f762
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions frontend/hooks/useFileSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,11 @@ export const useFileSystem = () => {

// If we're at the last segment, it's a file
if (index === segments.length - 1) {
// Check if the file already exists
if (!existingFiles.has(currentPath)) {
currentLevel.push({
name: segment,
type: 'file',
path: currentPath
});
}
currentLevel.push({
name: segment,
type: 'file',
path: currentPath
});
} else {
// It's a folder
let folder = currentLevel.find(
Expand Down Expand Up @@ -223,8 +220,8 @@ export const useFileSystem = () => {

// Update the file system state while preserving existing file contents
setFileSystem(prev => ({
...prev,
tree: newTree
tree: newTree,
files: prev.files // Preserve all existing file contents
}));
};

Expand Down

0 comments on commit 671f762

Please sign in to comment.