Files
spacedrive/packages/client/src/explorer/usePathsOffsetInfiniteQuery.ts
Vítor Vasconcellos ea92383b78 Improve file thumbnails and Quick Preview (+ some code clean-up and rust deps update) (#2758)
* Update rspc, prisma-client-rust, axum and tanstack-query
 - Deleted some unused examples and fully commented out frontend code
 - Implement many changes required due to the updates
 - Update most rust dependencies

* Re-enable p2p

* Fix server

* Auto format

* Fix injected script format
 - Update some github actions
 - Update pnpm lock file

* Fix devtools showing up when app opens
 - Fix million complaining about Sparkles component

* Fix sd-server

* Fix and improve thumbnails rendering
 - Fix core always saying a new thumbnail was generated even for files that it skiped thumbnail generation
 - Rewrite FileThumb and improve related components

* Ignore tmp files when running prettier

* Improve FileThumb component performance
 - Rework useExplorerDraggable and useExplorerItemData hooks due to reduce unecessary re-renders

* More fixes for thumb component
 - A couple of minor performance improvements to frontend code

* auto format

* Fix Thumbnail and QuickPreview

* Fix logic for when to show 'fail to load original' error message in QuickPreview
 - Updated prisma-client-rust, libp2p, tauri, tauri-specta, rspc and hyper

* Fix type checking
 - Format scripts

* Add script prettier config

* Fix serde missing feature
 - Use rust-libp2p spacedrive fork again
 - Update rspc

* Autoformat + fix pnpm lock

* Fix thumbnail first load again

* Autoformat

* autoformat

* Fix rust-libp2p fork url again?

* Remove usePathsInfiniteQuery hook

* Update tauri 2.0.6
2024-10-21 15:47:40 +00:00

58 lines
1.5 KiB
TypeScript

import { useInfiniteQuery } from '@tanstack/react-query';
import { FilePathOrder, FilePathSearchArgs } from '../core';
import { useLibraryContext } from '../hooks';
import { useRspcLibraryContext } from '../rspc';
import { UseExplorerInfiniteQueryArgs } from './useExplorerInfiniteQuery';
export function usePathsOffsetInfiniteQuery({
arg,
order
}: UseExplorerInfiniteQueryArgs<FilePathSearchArgs, FilePathOrder>) {
const take = arg.take ?? 100;
const { library } = useLibraryContext();
const ctx = useRspcLibraryContext();
if (order) {
arg.orderAndPagination = { orderOnly: order };
if (arg.orderAndPagination.orderOnly.field === 'sizeInBytes') delete arg.take;
}
const query = useInfiniteQuery({
queryKey: [
'search.paths',
{
library_id: library.uuid,
arg: { ...arg, take }
}
] satisfies [any, any],
queryFn: async ({ pageParam, queryKey: [_, { arg }] }) => {
let orderAndPagination: (typeof arg)['orderAndPagination'];
if (!pageParam) {
if (order) orderAndPagination = { orderOnly: order };
} else {
orderAndPagination = {
offset: {
order,
offset: pageParam * arg.take
}
};
}
arg.orderAndPagination = orderAndPagination;
const result = await ctx.client.query(['search.paths', arg]);
return { ...result, offset: pageParam, arg };
},
initialPageParam: 0,
getNextPageParam: ({ items, offset, arg }) => {
if (items.length >= arg.take) return (offset ?? 0) + 1;
}
});
return query;
}