Migrate hooks

This commit is contained in:
2024-10-10 21:12:37 +02:00
parent 76b4ed5d88
commit d29d402cf3
8 changed files with 105 additions and 131 deletions

View File

@@ -1,11 +1,9 @@
import { useState, useCallback } from 'react';
import { useToasts } from '@geist-ui/core';
import { notifications } from '@mantine/notifications';
import { lookupFileByName } from '../services/api';
import { DEFAULT_FILE } from '../utils/constants';
export const useFileNavigation = () => {
const { setToast } = useToasts();
const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path);
const [isNewFile, setIsNewFile] = useState(true);
@@ -21,17 +19,22 @@ export const useFileNavigation = () => {
if (filePaths.length >= 1) {
handleFileSelect(filePaths[0]);
} else {
setToast({ text: `File "${filename}" not found`, type: 'error' });
notifications.show({
title: 'File Not Found',
message: `File "${filename}" not found`,
color: 'red',
});
}
} catch (error) {
console.error('Error looking up file:', error);
setToast({
text: 'Failed to lookup file.',
type: 'error',
notifications.show({
title: 'Error',
message: 'Failed to lookup file.',
color: 'red',
});
}
},
[handleFileSelect, setToast]
[handleFileSelect]
);
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };