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.
This commit is contained in:
parent
e11bb16307
commit
827d5c58d0
@ -27,16 +27,26 @@ import ContentView from './ContentView'
|
|||||||
|
|
||||||
const FilesPage: FC = () => {
|
const FilesPage: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [fileType, setFileType] = useState<FileTypes | 'all' | 'gemini'>('all')
|
const [fileType, setFileType] = useState<FileType | 'document' | 'image' | 'text' | 'gemini'>('document')
|
||||||
const { providers } = useProviders()
|
const { providers } = useProviders()
|
||||||
|
|
||||||
const geminiProviders = providers.filter((provider) => provider.type === 'gemini')
|
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<FileType[]>(() => {
|
const files = useLiveQuery<FileType[]>(() => {
|
||||||
if (fileType === 'all') {
|
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])
|
}, [fileType])
|
||||||
|
|
||||||
const handleDelete = async (fileId: string) => {
|
const handleDelete = async (fileId: string) => {
|
||||||
@ -169,15 +179,15 @@ const FilesPage: FC = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
{ key: 'all', label: t('files.all'), icon: <FileTextOutlined /> },
|
{ key: FileTypes.DOCUMENT, label: t('files.document'), icon: <FilePdfOutlined /> },
|
||||||
{ key: FileTypes.IMAGE, label: t('files.image'), icon: <FileImageOutlined /> },
|
{ key: FileTypes.IMAGE, label: t('files.image'), icon: <FileImageOutlined /> },
|
||||||
{ key: FileTypes.TEXT, label: t('files.text'), icon: <FileTextOutlined /> },
|
{ key: FileTypes.TEXT, label: t('files.text'), icon: <FileTextOutlined /> },
|
||||||
{ key: FileTypes.DOCUMENT, label: t('files.document'), icon: <FilePdfOutlined /> },
|
|
||||||
...geminiProviders.map((provider) => ({
|
...geminiProviders.map((provider) => ({
|
||||||
key: 'gemini_' + provider.id,
|
key: 'gemini_' + provider.id,
|
||||||
label: provider.name,
|
label: provider.name,
|
||||||
icon: <FilePdfOutlined />
|
icon: <FilePdfOutlined />
|
||||||
}))
|
})),
|
||||||
|
{ key: 'all', label: t('files.all'), icon: <FileTextOutlined /> }
|
||||||
].filter(Boolean) as MenuProps['items']
|
].filter(Boolean) as MenuProps['items']
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user