mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-10-21 16:44:34 -04:00
* search options start * small progress * more * bunch of stuff * semi functioning filters * cleanup setup api * progress * remove filters * hooked up to query epic moment * fix * move db stuff to specific modules * in/notIn for some fields * generate ts * big gains * working filter options for locations, tags and kind * working search query * perfect fixed filters * saved searches lol * merge error * saved searches via api * better routing * [ENG-1338] Fix fresh Spacedrive install failing to start due to attempting to query a nonexistent Library (#1649) Fix Spacedrive failing to start due to attempting to query a nonexistent Library - Rename useShoudRedirect to useRedirectToNewLocations - Improve behaviour for the immedite redirection after adding a new location * Show hidden files false by default (#1652) bool * fix remove filter in list * tweaks * fix nav buttons * unify MediaData search handling * cleanup saved search writing * Add left top bar portals for tags and search + fixed media view on tags * added search to filter dropdown * render cycle improvements * hotfix * wip * Refactor with Brendan, but this is a WIP and the search query no longer works Co-authored-by: Brendan Allan <Brendonovich@users.noreply.github.com> * progress * fix location/$id page * fix tags too Co-authored-by: Brendan Allan <Brendonovich@users.noreply.github.com> * 3rd refactor lol epic style * half-done with enum-ification of SearchFilterArgs * broken fixed filters but working inNotIn filters * search name + extension kinda working * hidden filter * fixed filters working?? * deferred search value * extensions works * filtered search items mostly working * tweaks * stacked approach working for non-search filters * move to Explorer/Search * actually use filterArgs in queries things actually work properly now * added new icons from Mint * goof * cleanup types, filters and mutation logic * actually use search value * remove overview from sidebar * don't shrink LibrariesDropdown ga * remove overview from sidebar and default to /network --------- Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Co-authored-by: Brendan Allan <Brendonovich@users.noreply.github.com>
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
import {
|
|
ExplorerItem,
|
|
ObjectCursor,
|
|
ObjectOrder,
|
|
ObjectSearchArgs,
|
|
useRspcLibraryContext
|
|
} from '@sd/client';
|
|
|
|
import { UseExplorerInfiniteQueryArgs } from './useExplorerInfiniteQuery';
|
|
|
|
export function useObjectsInfiniteQuery({
|
|
library,
|
|
arg,
|
|
settings,
|
|
...args
|
|
}: UseExplorerInfiniteQueryArgs<ObjectSearchArgs, ObjectOrder>) {
|
|
const ctx = useRspcLibraryContext();
|
|
const explorerSettings = settings.useSettingsSnapshot();
|
|
|
|
if (explorerSettings.order) {
|
|
arg.orderAndPagination = { orderOnly: explorerSettings.order };
|
|
}
|
|
|
|
return useInfiniteQuery({
|
|
queryKey: ['search.objects', { library_id: library.uuid, arg }] as const,
|
|
queryFn: ({ pageParam, queryKey: [_, { arg }] }) => {
|
|
const cItem: Extract<ExplorerItem, { type: 'Object' }> = pageParam;
|
|
const { order } = explorerSettings;
|
|
|
|
let orderAndPagination: (typeof arg)['orderAndPagination'];
|
|
|
|
if (!cItem) {
|
|
if (order) orderAndPagination = { orderOnly: order };
|
|
} else {
|
|
let cursor: ObjectCursor | undefined;
|
|
|
|
if (!order) cursor = 'none';
|
|
else if (cItem) {
|
|
switch (order.field) {
|
|
case 'kind': {
|
|
const data = cItem.item.kind;
|
|
if (data !== null) cursor = { kind: { order: order.value, data } };
|
|
break;
|
|
}
|
|
case 'dateAccessed': {
|
|
const data = cItem.item.date_accessed;
|
|
if (data !== null)
|
|
cursor = { dateAccessed: { order: order.value, data } };
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (cursor) orderAndPagination = { cursor: { cursor, id: cItem.item.id } };
|
|
}
|
|
|
|
arg.orderAndPagination = orderAndPagination;
|
|
|
|
return ctx.client.query(['search.objects', arg]);
|
|
},
|
|
getNextPageParam: (lastPage) => {
|
|
if (lastPage.items.length < arg.take) return undefined;
|
|
else return lastPage.items[arg.take - 1];
|
|
},
|
|
...args
|
|
});
|
|
}
|