Fix file list reload after delete

This commit is contained in:
2024-10-13 16:13:47 +02:00
parent da5a3ebeee
commit b6e8a93d86
3 changed files with 17 additions and 7 deletions

View File

@@ -4,10 +4,12 @@ import Header from './Header';
import Sidebar from './Sidebar'; import Sidebar from './Sidebar';
import MainContent from './MainContent'; import MainContent from './MainContent';
import { useFileNavigation } from '../hooks/useFileNavigation'; import { useFileNavigation } from '../hooks/useFileNavigation';
import { useFileList } from '../hooks/useFileList';
const Layout = () => { const Layout = () => {
const { selectedFile, handleFileSelect, handleLinkClick } = const { selectedFile, handleFileSelect, handleLinkClick } =
useFileNavigation(); useFileNavigation();
const { files, loadFileList } = useFileList();
return ( return (
<AppShell header={{ height: 60 }} padding="md"> <AppShell header={{ height: 60 }} padding="md">
@@ -27,11 +29,14 @@ const Layout = () => {
<Sidebar <Sidebar
selectedFile={selectedFile} selectedFile={selectedFile}
handleFileSelect={handleFileSelect} handleFileSelect={handleFileSelect}
files={files}
loadFileList={loadFileList}
/> />
<MainContent <MainContent
selectedFile={selectedFile} selectedFile={selectedFile}
handleFileSelect={handleFileSelect} handleFileSelect={handleFileSelect}
handleLinkClick={handleLinkClick} handleLinkClick={handleLinkClick}
loadFileList={loadFileList}
/> />
</Container> </Container>
</AppShell.Main> </AppShell.Main>

View File

@@ -12,7 +12,12 @@ import { useFileOperations } from '../hooks/useFileOperations';
import { useGitOperations } from '../hooks/useGitOperations'; import { useGitOperations } from '../hooks/useGitOperations';
import { useSettings } from '../contexts/SettingsContext'; import { useSettings } from '../contexts/SettingsContext';
const MainContent = ({ selectedFile, handleFileSelect, handleLinkClick }) => { const MainContent = ({
selectedFile,
handleFileSelect,
handleLinkClick,
loadFileList,
}) => {
const [activeTab, setActiveTab] = useState('source'); const [activeTab, setActiveTab] = useState('source');
const { settings } = useSettings(); const { settings } = useSettings();
const { const {
@@ -43,20 +48,22 @@ const MainContent = ({ selectedFile, handleFileSelect, handleLinkClick }) => {
async (fileName) => { async (fileName) => {
const success = await handleCreate(fileName); const success = await handleCreate(fileName);
if (success) { if (success) {
loadFileList();
handleFileSelect(fileName); handleFileSelect(fileName);
} }
}, },
[handleCreate, handleFileSelect] [handleCreate, handleFileSelect, loadFileList]
); );
const handleDeleteFile = useCallback( const handleDeleteFile = useCallback(
async (filePath) => { async (filePath) => {
const success = await handleDelete(filePath); const success = await handleDelete(filePath);
if (success) { if (success) {
loadFileList();
handleFileSelect(null); handleFileSelect(null);
} }
}, },
[handleDelete, handleFileSelect] [handleDelete, handleFileSelect, loadFileList]
); );
const renderBreadcrumbs = useMemo(() => { const renderBreadcrumbs = useMemo(() => {

View File

@@ -2,18 +2,16 @@ import React, { useEffect } from 'react';
import { Box } from '@mantine/core'; import { Box } from '@mantine/core';
import FileActions from './FileActions'; import FileActions from './FileActions';
import FileTree from './FileTree'; import FileTree from './FileTree';
import { useFileList } from '../hooks/useFileList';
import { useGitOperations } from '../hooks/useGitOperations'; import { useGitOperations } from '../hooks/useGitOperations';
import { useSettings } from '../contexts/SettingsContext'; import { useSettings } from '../contexts/SettingsContext';
const Sidebar = ({ selectedFile, handleFileSelect }) => { const Sidebar = ({ selectedFile, handleFileSelect, files, loadFileList }) => {
const { settings } = useSettings(); const { settings } = useSettings();
const { files, loadFileList } = useFileList();
const { handlePull } = useGitOperations(settings.gitEnabled); const { handlePull } = useGitOperations(settings.gitEnabled);
useEffect(() => { useEffect(() => {
loadFileList(); loadFileList();
}, [settings.gitEnabled, loadFileList]); }, [loadFileList]);
return ( return (
<Box <Box