|
|
@ -8,23 +8,6 @@ import useDebouncedState from './useDebouncedState';
|
|
|
|
|
|
|
|
|
|
|
|
type Url = string | UrlObject;
|
|
|
|
type Url = string | UrlObject;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface SearchObject {
|
|
|
|
interface SearchObject {
|
|
|
|
searchValue: string;
|
|
|
|
searchValue: string;
|
|
|
|
searchOpen: boolean;
|
|
|
|
searchOpen: boolean;
|
|
|
@ -55,7 +38,7 @@ const useSearchInput = (): SearchObject => {
|
|
|
|
pathname: router.pathname,
|
|
|
|
pathname: router.pathname,
|
|
|
|
query: {
|
|
|
|
query: {
|
|
|
|
...router.query,
|
|
|
|
...router.query,
|
|
|
|
query: encodeURIExtraParams(debouncedValue),
|
|
|
|
query: debouncedValue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -63,7 +46,7 @@ const useSearchInput = (): SearchObject => {
|
|
|
|
router
|
|
|
|
router
|
|
|
|
.push({
|
|
|
|
.push({
|
|
|
|
pathname: '/search',
|
|
|
|
pathname: '/search',
|
|
|
|
query: { query: encodeURIExtraParams(debouncedValue) },
|
|
|
|
query: { query: debouncedValue },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(() => window.scrollTo(0, 0));
|
|
|
|
.then(() => window.scrollTo(0, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -106,7 +89,7 @@ const useSearchInput = (): SearchObject => {
|
|
|
|
* is on /search
|
|
|
|
* is on /search
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (router.query.query !== encodeURIExtraParams(debouncedValue)) {
|
|
|
|
if (router.query.query !== debouncedValue) {
|
|
|
|
setSearchValue(
|
|
|
|
setSearchValue(
|
|
|
|
router.query.query
|
|
|
|
router.query.query
|
|
|
|
? decodeURIComponent(router.query.query as string)
|
|
|
|
? decodeURIComponent(router.query.query as string)
|
|
|
|