mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 04:50:12 +02:00
update shared filter components
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { parseAsString, useQueryState } from 'nuqs';
|
||||
|
||||
import { FILTER_KEYS } from '/@/renderer/features/shared/utils';
|
||||
|
||||
export const useMusicFolderIdFilter = (defaultValue?: string) => {
|
||||
const [musicFolderId, setMusicFolderId] = useQueryState(
|
||||
FILTER_KEYS.SHARED.MUSIC_FOLDER_ID,
|
||||
defaultValue ? parseAsString.withDefault(defaultValue) : parseAsString,
|
||||
);
|
||||
|
||||
return {
|
||||
[FILTER_KEYS.SHARED.MUSIC_FOLDER_ID]: musicFolderId ?? undefined,
|
||||
setMusicFolderId,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useDebouncedValue } from '@mantine/hooks';
|
||||
import { parseAsString, useQueryState } from 'nuqs';
|
||||
|
||||
import { FILTER_KEYS } from '/@/renderer/features/shared/utils';
|
||||
|
||||
export const useSearchTermFilter = (defaultValue?: string) => {
|
||||
const [searchTerm, setSearchTerm] = useQueryState(
|
||||
FILTER_KEYS.SHARED.SEARCH_TERM,
|
||||
defaultValue ? parseAsString.withDefault(defaultValue) : parseAsString,
|
||||
);
|
||||
|
||||
const [debouncedSearchTerm] = useDebouncedValue(searchTerm, 300);
|
||||
|
||||
return {
|
||||
[FILTER_KEYS.SHARED.SEARCH_TERM]: debouncedSearchTerm ?? undefined,
|
||||
rawSearchTerm: searchTerm ?? undefined,
|
||||
setSearchTerm,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import { parseAsString, useQueryState } from 'nuqs';
|
||||
|
||||
import { FILTER_KEYS } from '/@/renderer/features/shared/utils';
|
||||
|
||||
export const useSortByFilter = <TSortBy>(defaultValue?: string) => {
|
||||
const [sortBy, setSortBy] = useQueryState(
|
||||
FILTER_KEYS.SHARED.SORT_BY,
|
||||
defaultValue ? parseAsString.withDefault(defaultValue) : parseAsString,
|
||||
);
|
||||
|
||||
return {
|
||||
[FILTER_KEYS.SHARED.SORT_BY]: (sortBy as TSortBy) ?? undefined,
|
||||
setSortBy,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { parseAsString, useQueryState } from 'nuqs';
|
||||
|
||||
import { FILTER_KEYS } from '/@/renderer/features/shared/utils';
|
||||
import { SortOrder } from '/@/shared/types/domain-types';
|
||||
|
||||
export const useSortOrderFilter = (defaultValue?: string) => {
|
||||
const [sortOrder, setSortOrder] = useQueryState(
|
||||
FILTER_KEYS.SHARED.SORT_ORDER,
|
||||
defaultValue ? parseAsString.withDefault(defaultValue) : parseAsString,
|
||||
);
|
||||
|
||||
return {
|
||||
[FILTER_KEYS.SHARED.SORT_ORDER]: (sortOrder as SortOrder) ?? undefined,
|
||||
setSortOrder,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user