Merge remote-tracking branch 'overseerr/develop' into develop

This commit is contained in:
notfakie
2023-01-27 17:55:55 +13:00
158 changed files with 10835 additions and 4524 deletions

View File

@@ -27,9 +27,30 @@ interface DiscoverResult<T, S> {
firstResultData?: BaseSearchResult<T> & S;
}
const useDiscover = <T extends BaseMedia, S = Record<string, never>>(
const extraEncodes: [RegExp, string][] = [
[/\(/g, '%28'],
[/\)/g, '%29'],
[/!/g, '%21'],
[/\*/g, '%2A'],
];
export const encodeURIExtraParams = (string: string): string => {
let finalString = encodeURIComponent(string);
extraEncodes.forEach((encode) => {
finalString = finalString.replace(encode[0], encode[1]);
});
return finalString;
};
const useDiscover = <
T extends BaseMedia,
S = Record<string, never>,
O = Record<string, unknown>
>(
endpoint: string,
options?: Record<string, unknown>,
options?: O,
{ hideAvailable = true } = {}
): DiscoverResult<T, S> => {
const settings = useSettings();
@@ -47,7 +68,10 @@ const useDiscover = <T extends BaseMedia, S = Record<string, never>>(
};
const finalQueryString = Object.keys(params)
.map((paramKey) => `${paramKey}=${params[paramKey]}`)
.map(
(paramKey) =>
`${paramKey}=${encodeURIExtraParams(params[paramKey] as string)}`
)
.join('&');
return `${endpoint}?${finalQueryString}`;

View File

@@ -8,23 +8,6 @@ import useDebouncedState from './useDebouncedState';
type Url = string | UrlObject;
const extraEncodes: [RegExp, string][] = [
[/\(/g, '%28'],
[/\)/g, '%29'],
[/!/g, '%21'],
[/\*/g, '%2A'],
];
const encodeURIExtraParams = (string: string): string => {
let finalString = encodeURIComponent(string);
extraEncodes.forEach((encode) => {
finalString = finalString.replace(encode[0], encode[1]);
});
return finalString;
};
interface SearchObject {
searchValue: string;
searchOpen: boolean;
@@ -55,7 +38,7 @@ const useSearchInput = (): SearchObject => {
pathname: router.pathname,
query: {
...router.query,
query: encodeURIExtraParams(debouncedValue),
query: debouncedValue,
},
});
} else {
@@ -63,7 +46,7 @@ const useSearchInput = (): SearchObject => {
router
.push({
pathname: '/search',
query: { query: encodeURIExtraParams(debouncedValue) },
query: { query: debouncedValue },
})
.then(() => window.scrollTo(0, 0));
}
@@ -106,7 +89,7 @@ const useSearchInput = (): SearchObject => {
* is on /search
*/
useEffect(() => {
if (router.query.query !== encodeURIExtraParams(debouncedValue)) {
if (router.query.query !== debouncedValue) {
setSearchValue(
router.query.query
? decodeURIComponent(router.query.query as string)

View File

@@ -132,3 +132,20 @@ export const useUpdateQueryParams = (
[filter, updateQueryParams]
);
};
export const useBatchUpdateQueryParams = (
filter: ParsedUrlQuery
): ((items: Record<string, string | undefined>) => void) => {
const updateQueryParams = useQueryParams();
return useCallback(
(items: Record<string, string | undefined>) => {
const query = {
...filter,
...items,
};
updateQueryParams(query, 'replace');
},
[filter, updateQueryParams]
);
};

View File

@@ -2,8 +2,8 @@ import { UserType } from '@server/constants/user';
import type { PermissionCheckOptions } from '@server/lib/permissions';
import { hasPermission, Permission } from '@server/lib/permissions';
import type { NotificationAgentKey } from '@server/lib/settings';
import type { MutatorCallback } from 'swr';
import useSWR from 'swr';
import type { MutatorCallback } from 'swr/dist/types';
export { Permission, UserType };
export type { PermissionCheckOptions };