mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 00:14:25 +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 { notifications } from '@mantine/notifications';
|
||||||
import { lookupFileByName } from '../services/api';
|
import { lookupFileByName } from '../services/api';
|
||||||
import { DEFAULT_FILE } from '../utils/constants';
|
import { DEFAULT_FILE } from '../utils/constants';
|
||||||
@@ -10,8 +10,8 @@ export const useFileNavigation = () => {
|
|||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
|
||||||
const handleFileSelect = useCallback((filePath) => {
|
const handleFileSelect = useCallback((filePath) => {
|
||||||
setSelectedFile(filePath);
|
setSelectedFile(filePath || DEFAULT_FILE.path);
|
||||||
setIsNewFile(filePath === DEFAULT_FILE.path);
|
setIsNewFile(filePath ? false : true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleLinkClick = useCallback(
|
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 };
|
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user