Fix some props issues

This commit is contained in:
2024-10-05 23:15:35 +02:00
parent 9de434ff2e
commit 6406265df6
5 changed files with 17 additions and 14 deletions

View File

@@ -1,8 +1,7 @@
// hooks/useFileNavigation.js
import { useState, useCallback } from 'react';
import { useToasts } from '@geist-ui/core';
import { lookupFileByName } from '../services/api';
import { DEFAULT_FILE } from '../utils/constants'; // Assuming you have this constant defined
import { DEFAULT_FILE } from '../utils/constants';
export const useFileNavigation = () => {
const { setToast } = useToasts();
@@ -10,6 +9,11 @@ export const useFileNavigation = () => {
const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path);
const [isNewFile, setIsNewFile] = useState(true);
const handleFileSelect = useCallback((filePath) => {
setSelectedFile(filePath);
setIsNewFile(filePath === DEFAULT_FILE.path);
}, []);
const handleLinkClick = useCallback(
async (filename) => {
try {
@@ -27,13 +31,8 @@ export const useFileNavigation = () => {
});
}
},
[handleFileSelect]
[handleFileSelect, setToast]
);
const handleFileSelect = useCallback(async (filePath) => {
setSelectedFile(filePath);
setIsNewFile(filePath === DEFAULT_FILE.path);
}, []);
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };
};