mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Remove more contexts
This commit is contained in:
@@ -1,38 +1,39 @@
|
||||
// hooks/useFileNavigation.js
|
||||
import { useCallback } from 'react';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useToasts } from '@geist-ui/core';
|
||||
import { lookupFileByName } from '../services/api';
|
||||
import { useFileSelection } from '../contexts/FileSelectionContext';
|
||||
import { DEFAULT_FILE } from '../utils/constants'; // Assuming you have this constant defined
|
||||
|
||||
export const useFileNavigation = () => {
|
||||
const { setToast } = useToasts();
|
||||
const { handleFileSelect } = useFileSelection();
|
||||
|
||||
const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path);
|
||||
const [isNewFile, setIsNewFile] = useState(true);
|
||||
|
||||
const handleLinkClick = useCallback(
|
||||
async (filename) => {
|
||||
try {
|
||||
const filePaths = await lookupFileByName(filename);
|
||||
if (filePaths.length === 1) {
|
||||
if (filePaths.length >= 1) {
|
||||
handleFileSelect(filePaths[0]);
|
||||
} else if (filePaths.length > 1) {
|
||||
// Handle multiple file options (you may want to show a modal or dropdown)
|
||||
setToast({
|
||||
text: 'Multiple files found with the same name. Please specify the full path.',
|
||||
type: 'warning',
|
||||
});
|
||||
} else {
|
||||
setToast({ text: `File "${filename}" not found`, type: 'error' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error looking up file:', error);
|
||||
setToast({
|
||||
text: 'Failed to lookup file. Please try again.',
|
||||
text: 'Failed to lookup file.',
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
},
|
||||
[handleFileSelect, setToast]
|
||||
[handleFileSelect]
|
||||
);
|
||||
|
||||
return { handleLinkClick };
|
||||
const handleFileSelect = useCallback(async (filePath) => {
|
||||
setSelectedFile(filePath);
|
||||
setIsNewFile(filePath === DEFAULT_FILE.path);
|
||||
}, []);
|
||||
|
||||
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user