Skip to content

Commit

Permalink
fix: prevent double encode if we are on /search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
OwsleyJr committed Jan 13, 2023
1 parent c2a1a20 commit 252fdca
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hooks/useDiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ const useDiscover = <
return null;
}

const paramsEncodeCheck = (
params: Record<string, unknown>,
paramKey: string
) =>
endpoint.includes('/search')
? params[paramKey]
: encodeURIExtraParams(params[paramKey] as string);

const params: Record<string, unknown> = {
page: pageIndex + 1,
...options,
};

const finalQueryString = Object.keys(params)
.map(
(paramKey) =>
`${paramKey}=${encodeURIExtraParams(params[paramKey] as string)}`
)
.map((paramKey) => `${paramKey}=${paramsEncodeCheck(params, paramKey)}`)
.join('&');

return `${endpoint}?${finalQueryString}`;
Expand Down

0 comments on commit 252fdca

Please sign in to comment.