From 827d5c58d0ab2347e2c56ae14fbf694e5edae958 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Mon, 17 Mar 2025 15:24:26 +0800 Subject: [PATCH] refactor: update file type handling and sorting in FilesPage component - Changed the default file type state to 'document' for better initial filtering. - Introduced a temporary file sorting function to prioritize non-temporary files in the displayed list. - Adjusted the file retrieval logic to apply sorting consistently for both 'all' and specific file types. --- src/renderer/src/pages/files/FilesPage.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/pages/files/FilesPage.tsx b/src/renderer/src/pages/files/FilesPage.tsx index 596c083f..4ff9e843 100644 --- a/src/renderer/src/pages/files/FilesPage.tsx +++ b/src/renderer/src/pages/files/FilesPage.tsx @@ -27,16 +27,26 @@ import ContentView from './ContentView' const FilesPage: FC = () => { const { t } = useTranslation() - const [fileType, setFileType] = useState('all') + const [fileType, setFileType] = useState('document') const { providers } = useProviders() const geminiProviders = providers.filter((provider) => provider.type === 'gemini') + const tempFilesSort = (files: FileType[]) => { + return files.sort((a, b) => { + const aIsTemp = a.origin_name.startsWith('temp_file') + const bIsTemp = b.origin_name.startsWith('temp_file') + if (aIsTemp && !bIsTemp) return 1 + if (!aIsTemp && bIsTemp) return -1 + return 0 + }) + } + const files = useLiveQuery(() => { if (fileType === 'all') { - return db.files.orderBy('count').toArray() + return db.files.orderBy('count').toArray().then(tempFilesSort) } - return db.files.where('type').equals(fileType).sortBy('count') + return db.files.where('type').equals(fileType).sortBy('count').then(tempFilesSort) }, [fileType]) const handleDelete = async (fileId: string) => { @@ -169,15 +179,15 @@ const FilesPage: FC = () => { ) const menuItems = [ - { key: 'all', label: t('files.all'), icon: }, + { key: FileTypes.DOCUMENT, label: t('files.document'), icon: }, { key: FileTypes.IMAGE, label: t('files.image'), icon: }, { key: FileTypes.TEXT, label: t('files.text'), icon: }, - { key: FileTypes.DOCUMENT, label: t('files.document'), icon: }, ...geminiProviders.map((provider) => ({ key: 'gemini_' + provider.id, label: provider.name, icon: - })) + })), + { key: 'all', label: t('files.all'), icon: } ].filter(Boolean) as MenuProps['items'] return (