Remove FileList, FileOps and GitOps contexts

This commit is contained in:
2024-10-05 12:12:51 +02:00
parent 96e0d1b73d
commit 5ea932c96e
13 changed files with 114 additions and 148 deletions

View File

@@ -1,7 +1,6 @@
import { useEffect, useCallback } from 'react';
import { useFileSelection } from './useFileSelection';
import { useFileContent } from './useFileContent';
import { useFileOperations } from './useFileOperations';
export const useFileManagement = () => {
const { selectedFile, isNewFile, handleFileSelect } = useFileSelection();
@@ -12,10 +11,7 @@ export const useFileManagement = () => {
hasUnsavedChanges,
loadFileContent,
handleContentChange,
setHasUnsavedChanges,
} = useFileContent();
const { handleSave, handleDelete, handleCreateNewFile } =
useFileOperations(setHasUnsavedChanges);
useEffect(() => {
if (selectedFile) {
@@ -40,8 +36,5 @@ export const useFileManagement = () => {
hasUnsavedChanges,
handleFileSelect: handleFileSelectAndLoad,
handleContentChange,
handleSave: (filePath) => handleSave(filePath, content),
handleDelete,
handleCreateNewFile,
};
};

View File

@@ -16,7 +16,6 @@ export const useFileNavigation = () => {
handleFileSelect(filePaths[0]);
} else if (filePaths.length > 1) {
// Handle multiple file options (you may want to show a modal or dropdown)
console.log('Multiple files found:', filePaths);
setToast({
text: 'Multiple files found with the same name. Please specify the full path.',
type: 'warning',

View File

@@ -32,19 +32,16 @@ export const useFileOperations = (setHasUnsavedChanges) => {
}
}, []);
const handleCreateNewFile = useCallback(
async (fileName, initialContent = '') => {
try {
await saveFileContent(fileName, initialContent);
return true;
} catch (error) {
setToast({ text: `Error creating new file`, type: 'error' });
console.error('Error creating new file:', error);
return false;
}
},
[]
);
const handleCreate = useCallback(async (fileName, initialContent = '') => {
try {
await saveFileContent(fileName, initialContent);
return true;
} catch (error) {
setToast({ text: `Error creating new file`, type: 'error' });
console.error('Error creating new file:', error);
return false;
}
}, []);
return { handleSave, handleDelete, handleCreateNewFile };
return { handleSave, handleDelete, handleCreate };
};