mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 20:40:15 +02:00
more fixes to list filters
This commit is contained in:
@@ -155,23 +155,28 @@ export const useAlbumListFilters = () => {
|
||||
|
||||
const setCustom = useCallback(
|
||||
(value: null | Record<string, any>) => {
|
||||
setSearchParams((prev) => {
|
||||
const previousValue = prev.get(FILTER_KEYS.ALBUM._CUSTOM);
|
||||
setSearchParams(
|
||||
(prev) => {
|
||||
const previousValue = prev.get(FILTER_KEYS.ALBUM._CUSTOM);
|
||||
|
||||
const newCustom = {
|
||||
...(previousValue ? JSON.parse(previousValue) : {}),
|
||||
...value,
|
||||
};
|
||||
const newCustom = {
|
||||
...(previousValue ? JSON.parse(previousValue) : {}),
|
||||
...value,
|
||||
};
|
||||
|
||||
const filteredNewCustom = Object.fromEntries(
|
||||
Object.entries(newCustom).filter(
|
||||
([, value]) => value !== null && value !== undefined,
|
||||
),
|
||||
);
|
||||
const filteredNewCustom = Object.fromEntries(
|
||||
Object.entries(newCustom).filter(
|
||||
([, value]) => value !== null && value !== undefined,
|
||||
),
|
||||
);
|
||||
|
||||
prev.set(FILTER_KEYS.ALBUM._CUSTOM, JSON.stringify(filteredNewCustom));
|
||||
return prev;
|
||||
});
|
||||
prev.set(FILTER_KEYS.ALBUM._CUSTOM, JSON.stringify(filteredNewCustom));
|
||||
return prev;
|
||||
},
|
||||
{
|
||||
replace: true,
|
||||
},
|
||||
);
|
||||
},
|
||||
[setSearchParams],
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useSearchTermFilter } from '/@/renderer/features/shared/hooks/use-searc
|
||||
import { useSortByFilter } from '/@/renderer/features/shared/hooks/use-sort-by-filter';
|
||||
import { useSortOrderFilter } from '/@/renderer/features/shared/hooks/use-sort-order-filter';
|
||||
import { FILTER_KEYS } from '/@/renderer/features/shared/utils';
|
||||
import { parseCustomFiltersParam, setJsonSearchParam } from '/@/renderer/utils/query-params';
|
||||
import { parseCustomFiltersParam } from '/@/renderer/utils/query-params';
|
||||
import { PlaylistListSort } from '/@/shared/types/domain-types';
|
||||
import { ItemListKey } from '/@/shared/types/types';
|
||||
|
||||
@@ -23,31 +23,28 @@ export const usePlaylistListFilters = () => {
|
||||
);
|
||||
|
||||
const setCustom = useCallback(
|
||||
(
|
||||
value:
|
||||
| ((prev: null | Record<string, any>) => null | Record<string, any>)
|
||||
| null
|
||||
| Record<string, any>,
|
||||
) => {
|
||||
(value: null | Record<string, any>) => {
|
||||
setSearchParams(
|
||||
(prev) => {
|
||||
const currentCustom = parseCustomFiltersParam(
|
||||
prev,
|
||||
FILTER_KEYS.PLAYLIST.CUSTOM,
|
||||
const previousValue = prev.get(FILTER_KEYS.ALBUM._CUSTOM);
|
||||
|
||||
const newCustom = {
|
||||
...(previousValue ? JSON.parse(previousValue) : {}),
|
||||
...value,
|
||||
};
|
||||
|
||||
const filteredNewCustom = Object.fromEntries(
|
||||
Object.entries(newCustom).filter(
|
||||
([, value]) => value !== null && value !== undefined,
|
||||
),
|
||||
);
|
||||
let newValue =
|
||||
typeof value === 'function' ? value(currentCustom ?? null) : value;
|
||||
// Convert empty objects to null to clear them from URL
|
||||
if (
|
||||
newValue &&
|
||||
typeof newValue === 'object' &&
|
||||
Object.keys(newValue).length === 0
|
||||
) {
|
||||
newValue = null;
|
||||
}
|
||||
return setJsonSearchParam(prev, FILTER_KEYS.PLAYLIST.CUSTOM, newValue);
|
||||
|
||||
prev.set(FILTER_KEYS.ALBUM._CUSTOM, JSON.stringify(filteredNewCustom));
|
||||
return prev;
|
||||
},
|
||||
{
|
||||
replace: true,
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
},
|
||||
[setSearchParams],
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
parseBooleanParam,
|
||||
parseCustomFiltersParam,
|
||||
parseIntParam,
|
||||
setJsonSearchParam,
|
||||
setSearchParam,
|
||||
} from '/@/renderer/utils/query-params';
|
||||
import { SongListSort, SortOrder } from '/@/shared/types/domain-types';
|
||||
@@ -115,28 +114,28 @@ export const usePlaylistSongListFilters = () => {
|
||||
);
|
||||
|
||||
const setCustom = useCallback(
|
||||
(
|
||||
value:
|
||||
| ((prev: null | Record<string, any>) => null | Record<string, any>)
|
||||
| null
|
||||
| Record<string, any>,
|
||||
) => {
|
||||
(value: null | Record<string, any>) => {
|
||||
setSearchParams(
|
||||
(prev) => {
|
||||
const currentCustom = parseCustomFiltersParam(prev, FILTER_KEYS.SONG._CUSTOM);
|
||||
let newValue =
|
||||
typeof value === 'function' ? value(currentCustom ?? null) : value;
|
||||
// Convert empty objects to null to clear them from URL
|
||||
if (
|
||||
newValue &&
|
||||
typeof newValue === 'object' &&
|
||||
Object.keys(newValue).length === 0
|
||||
) {
|
||||
newValue = null;
|
||||
}
|
||||
return setJsonSearchParam(prev, FILTER_KEYS.SONG._CUSTOM, newValue);
|
||||
const previousValue = prev.get(FILTER_KEYS.ALBUM._CUSTOM);
|
||||
|
||||
const newCustom = {
|
||||
...(previousValue ? JSON.parse(previousValue) : {}),
|
||||
...value,
|
||||
};
|
||||
|
||||
const filteredNewCustom = Object.fromEntries(
|
||||
Object.entries(newCustom).filter(
|
||||
([, value]) => value !== null && value !== undefined,
|
||||
),
|
||||
);
|
||||
|
||||
prev.set(FILTER_KEYS.ALBUM._CUSTOM, JSON.stringify(filteredNewCustom));
|
||||
return prev;
|
||||
},
|
||||
{
|
||||
replace: true,
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
},
|
||||
[setSearchParams],
|
||||
|
||||
Reference in New Issue
Block a user