mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
41 lines
933 B
JavaScript
41 lines
933 B
JavaScript
import { useEffect, useCallback } from 'react';
|
|
import { useFileSelection } from './useFileSelection';
|
|
import { useFileContent } from './useFileContent';
|
|
|
|
export const useFileManagement = () => {
|
|
const { selectedFile, isNewFile, handleFileSelect } = useFileSelection();
|
|
const {
|
|
content,
|
|
isLoading,
|
|
error,
|
|
hasUnsavedChanges,
|
|
loadFileContent,
|
|
handleContentChange,
|
|
} = useFileContent();
|
|
|
|
useEffect(() => {
|
|
if (selectedFile) {
|
|
loadFileContent(selectedFile);
|
|
}
|
|
}, [selectedFile, loadFileContent]);
|
|
|
|
const handleFileSelectAndLoad = useCallback(
|
|
async (filePath) => {
|
|
await handleFileSelect(filePath);
|
|
await loadFileContent(filePath);
|
|
},
|
|
[handleFileSelect, loadFileContent]
|
|
);
|
|
|
|
return {
|
|
selectedFile,
|
|
isNewFile,
|
|
content,
|
|
isLoading,
|
|
error,
|
|
hasUnsavedChanges,
|
|
handleFileSelect: handleFileSelectAndLoad,
|
|
handleContentChange,
|
|
};
|
|
};
|