refactor: remove compatibility patch logic and unused imports from getServerSideProps and RicercaProvider
This commit is contained in:
parent
e1f7c888f3
commit
c280196719
2 changed files with 1 additions and 43 deletions
|
|
@ -39,7 +39,6 @@ import { cn, debounce } from "~/lib/utils";
|
|||
import { useTranslation } from "~/providers/I18nProvider";
|
||||
import {
|
||||
type AnnunciOptions,
|
||||
compatibilityPatch,
|
||||
RicercaProvider,
|
||||
type SortTypes,
|
||||
useRicerca,
|
||||
|
|
@ -94,21 +93,9 @@ Annunci.getLayout = (page: React.ReactNode) => {
|
|||
return <Layout>{page}</Layout>;
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const getServerSideProps = (async (ctx) => {
|
||||
export const getServerSideProps = (async () => {
|
||||
const helper = generateSSGHelper();
|
||||
const options = await helper.annunci.getAnnunciOptions.fetch();
|
||||
const {patched, query} = compatibilityPatch(ctx.query);
|
||||
if (patched){
|
||||
const queryString = new URLSearchParams(query as Record<string, string>).toString();
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/annunci?${queryString}`,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
options,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {
|
|||
parseAsStringLiteral,
|
||||
useQueryState,
|
||||
} from "nuqs";
|
||||
import type { ParsedUrlQuery } from "querystring";
|
||||
import {
|
||||
createContext,
|
||||
type FC,
|
||||
|
|
@ -229,31 +228,3 @@ export const RicercaProvider: FC<{
|
|||
</RicercaContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const acceptedParams = ["m", "t", "c", "f", "bmin", "bmax", "s"];
|
||||
const patchedParams = {
|
||||
map: "m",
|
||||
tipo: "t",
|
||||
comune: "c",
|
||||
consegna: "f",
|
||||
minBudget: "bmin",
|
||||
maxBudget: "bmax",
|
||||
sort: "s",
|
||||
};
|
||||
export const compatibilityPatch = (query: ParsedUrlQuery) => {
|
||||
let patched = false;
|
||||
for (const key of Object.keys(query)) {
|
||||
if (!acceptedParams.includes(key)) {
|
||||
if (Object.keys(patchedParams).includes(key)) {
|
||||
const mappedKey = patchedParams[key as keyof typeof patchedParams];
|
||||
if (mappedKey) {
|
||||
const value = query[key];
|
||||
delete query[key];
|
||||
query[mappedKey] = value;
|
||||
patched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return { patched, query };
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue