function cleanParams()

in src/pages/Home/useHomeParameters.ts [48:66]


function cleanParams(qp: ParametersMap): Record<string, string> {
  if (typeof qp !== 'object' || !qp) return {};

  const fn = (obj: Record<string, string>, key: keyof ParametersMap): Record<string, string> => {
    // Unfortunately withDefault of use-query-params does not default in case of empty string so we need to
    // assing default value for status here by hand

    const value = key === 'status' && qp[key] === '' ? defaultHomeParameters.status : qp[key];

    if (value) {
      return { ...obj, [key as string]: value } as Record<string, string>;
    }
    return obj;
  };

  const keys = Object.keys(qp) as (keyof ParametersMap)[];

  return keys.reduce(fn, {});
}