1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-21 22:05:38 -04:00
Files
Sonarr/frontend/src/Utilities/Fetch/getQueryString.ts
T
Mark McDowall 5f359e975d Use react-query for queue UI
New: Season packs and multi-episode releases will show as a single item in the queue
Closes #6537
2025-08-30 14:09:00 -07:00

51 lines
1.0 KiB
TypeScript

import { PropertyFilter } from 'App/State/AppState';
export interface QueryParams {
[key: string]:
| string
| number
| boolean
| PropertyFilter[]
| number[]
| undefined;
}
const getQueryString = (queryParams?: QueryParams) => {
if (!queryParams) {
return '';
}
const searchParams = Object.keys(queryParams).reduce<URLSearchParams>(
(acc, key) => {
const value = queryParams[key];
if (value == null) {
return acc;
}
if (Array.isArray(value)) {
if (typeof value[0] === 'object') {
(value as PropertyFilter[]).forEach((filter) => {
acc.append(filter.key, String(filter.value));
});
} else {
value.forEach((item) => {
acc.append(key, String(item));
});
}
} else {
acc.append(key, String(value));
}
return acc;
},
new URLSearchParams()
);
const paramsString = searchParams.toString();
return `?${paramsString}`;
};
export default getQueryString;