Fix duplicate file list requests

This commit is contained in:
2024-10-06 12:58:43 +02:00
parent cf4378edf6
commit 9bad569ca3
3 changed files with 6 additions and 17 deletions

View File

@@ -14,9 +14,11 @@ import { useFileList } from '../hooks/useFileList';
import { useFileOperations } from '../hooks/useFileOperations';
import { useGitOperations } from '../hooks/useGitOperations';
import { useFileNavigation } from '../hooks/useFileNavigation';
import { useSettings } from '../contexts/SettingsContext';
const MainContent = () => {
const [activeTab, setActiveTab] = useState('source');
const { settings } = useSettings();
const { files, loadFileList } = useFileList();
const { handleLinkClick, selectedFile, handleFileSelect } =
useFileNavigation();
@@ -31,7 +33,7 @@ const MainContent = () => {
useEffect(() => {
loadFileList();
}, [loadFileList]);
}, [settings.gitEnabled]);
const handleTabChange = (value) => {
setActiveTab(value);

View File

@@ -1,5 +1,6 @@
import React, { createContext, useState, useContext, useEffect } from 'react';
import { fetchUserSettings, saveUserSettings } from '../services/api';
import { DEFAULT_SETTINGS } from '../utils/constants';
const SettingsContext = createContext();
@@ -8,17 +9,7 @@ export const useSettings = () => {
};
export const SettingsProvider = ({ children }) => {
const [settings, setSettings] = useState({
theme: 'light',
autoSave: false,
gitEnabled: false,
gitUrl: '',
gitUser: '',
gitToken: '',
gitAutoCommit: false,
gitCommitMsgTemplate: '',
});
const [settings, setSettings] = useState(DEFAULT_SETTINGS);
const [loading, setLoading] = useState(true);
useEffect(() => {

View File

@@ -1,7 +1,7 @@
import { useState, useEffect, useCallback } from 'react';
import { fetchFileList } from '../services/api';
export const useFileList = (gitEnabled) => {
export const useFileList = () => {
const [files, setFiles] = useState([]);
const loadFileList = useCallback(async () => {
@@ -17,9 +17,5 @@ export const useFileList = (gitEnabled) => {
}
}, []);
useEffect(() => {
loadFileList();
}, [gitEnabled]);
return { files, loadFileList };
};