mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Select default files when no files listed
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useState, useCallback, useEffect } from 'react'; // Added useEffect
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { lookupFileByName } from '../services/api';
|
||||
import { DEFAULT_FILE } from '../utils/constants';
|
||||
@@ -10,8 +10,8 @@ export const useFileNavigation = () => {
|
||||
const { currentWorkspace } = useWorkspace();
|
||||
|
||||
const handleFileSelect = useCallback((filePath) => {
|
||||
setSelectedFile(filePath);
|
||||
setIsNewFile(filePath === DEFAULT_FILE.path);
|
||||
setSelectedFile(filePath || DEFAULT_FILE.path);
|
||||
setIsNewFile(filePath ? false : true);
|
||||
}, []);
|
||||
|
||||
const handleLinkClick = useCallback(
|
||||
@@ -38,8 +38,13 @@ export const useFileNavigation = () => {
|
||||
});
|
||||
}
|
||||
},
|
||||
[currentWorkspace]
|
||||
[currentWorkspace, handleFileSelect]
|
||||
);
|
||||
|
||||
// Reset to default file when workspace changes
|
||||
useEffect(() => {
|
||||
handleFileSelect(null);
|
||||
}, [currentWorkspace, handleFileSelect]);
|
||||
|
||||
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user