diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 7ba525f..44f415d 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -125,13 +125,6 @@ pub async fn get_directory_files( ]) .order_by(file::path::order(Direction::Asc)); - // if let Some(path) = cursor_path { - // query = query.cursor(file::path::equals(path)).skip(1) - // } - // if let Some(s) = skip { - // query = query.skip(s) - // } - return match query.skip(skip).take(20).exec().await { Ok(files) => Ok(files), Err(e) => Err(e.to_string()), diff --git a/src/components/FilesTable/FilesTable.tsx b/src/components/FilesTable/FilesTable.tsx index 0ea092e..07518d4 100644 --- a/src/components/FilesTable/FilesTable.tsx +++ b/src/components/FilesTable/FilesTable.tsx @@ -77,7 +77,11 @@ const FilesTable: Component = () => { const rowVirtualizer = createVirtualizer({ getScrollElement: () => bodyTableRef, get count() { - return metadataFiles()?.total_count ?? 0; + if (!metadataFiles.loading) { + return metadataFiles()?.total_count || 0; + } else { + return files()?.length || 0; + } }, overscan: 8, estimateSize: () => 45, diff --git a/src/components/FilesTable/hooks/useFilesLoader.ts b/src/components/FilesTable/hooks/useFilesLoader.ts index 7479f83..85f5faa 100644 --- a/src/components/FilesTable/hooks/useFilesLoader.ts +++ b/src/components/FilesTable/hooks/useFilesLoader.ts @@ -1,19 +1,11 @@ import { - FetchMetadataFilesKeys, + ShareDirectoryFilesKeys, getDirectoryFiles, getMetadataFiles, - type FetchDirectoryFilesKeys, } from "@/services/filesServices"; import { MetadataFiles } from "@/services/helpers/helpers"; import { type File as PrismaFile } from "@prisma/client"; -import { - Accessor, - Resource, - createEffect, - createResource, - createSignal, - on, -} from "solid-js"; +import { Accessor, Resource, createResource } from "solid-js"; import { DEFAULT_ITEM_PER_PAGE } from "../constants"; const getCurrentSkipItems = (index: number): number => { @@ -25,43 +17,33 @@ const getCurrentSkipItems = (index: number): number => { interface IFilesLoaderResult { files: Resource; metadataFiles: Resource; - handleSkipUpdate: (value: number) => number; + handleSkipUpdate: (value: number) => void; } const useFilesLoader: ( paths: Accessor, search: Accessor ) => IFilesLoaderResult = (paths, search) => { - const [skip, setSkip] = createSignal(0); - const [metadataFiles] = createResource< MetadataFiles, - FetchMetadataFilesKeys, + ShareDirectoryFilesKeys, boolean >(() => [paths(), search()], getMetadataFiles); - const [files, { mutate: mutateFiles }] = createResource< + const [files, { refetch: refetchFiles }] = createResource< PrismaFile[], - FetchDirectoryFilesKeys, - boolean - >(() => [paths(), search(), skip()], getDirectoryFiles); - - createEffect( - on( - [paths, search], - () => { - mutateFiles([]); - setSkip(0); - }, - { defer: true } - ) - ); + ShareDirectoryFilesKeys, + number + >(() => [paths(), search()], getDirectoryFiles); return { files, metadataFiles, handleSkipUpdate: (value) => { - return setSkip(getCurrentSkipItems(value || 0)); + const currentSkipItems = getCurrentSkipItems(value || 0); + if (currentSkipItems) { + refetchFiles(currentSkipItems); + } }, }; }; diff --git a/src/components/Tabs/Tabs.tsx b/src/components/Tabs/Tabs.tsx index 946771f..2cd7a8c 100644 --- a/src/components/Tabs/Tabs.tsx +++ b/src/components/Tabs/Tabs.tsx @@ -32,12 +32,16 @@ const Tabs: FlowComponent> = (props) => { onClick={() => props.setActive(index())} class="tab flex-shrink-0" classList={{ - "tab-active": item.active + "tab-active": item.active, }} > -