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 { useTranslation } from "~/providers/I18nProvider";
|
||||||
import {
|
import {
|
||||||
type AnnunciOptions,
|
type AnnunciOptions,
|
||||||
compatibilityPatch,
|
|
||||||
RicercaProvider,
|
RicercaProvider,
|
||||||
type SortTypes,
|
type SortTypes,
|
||||||
useRicerca,
|
useRicerca,
|
||||||
|
|
@ -94,21 +93,9 @@ Annunci.getLayout = (page: React.ReactNode) => {
|
||||||
return <Layout>{page}</Layout>;
|
return <Layout>{page}</Layout>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getServerSideProps = (async () => {
|
||||||
|
|
||||||
export const getServerSideProps = (async (ctx) => {
|
|
||||||
const helper = generateSSGHelper();
|
const helper = generateSSGHelper();
|
||||||
const options = await helper.annunci.getAnnunciOptions.fetch();
|
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 {
|
return {
|
||||||
props: {
|
props: {
|
||||||
options,
|
options,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import {
|
||||||
parseAsStringLiteral,
|
parseAsStringLiteral,
|
||||||
useQueryState,
|
useQueryState,
|
||||||
} from "nuqs";
|
} from "nuqs";
|
||||||
import type { ParsedUrlQuery } from "querystring";
|
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
type FC,
|
type FC,
|
||||||
|
|
@ -229,31 +228,3 @@ export const RicercaProvider: FC<{
|
||||||
</RicercaContext.Provider>
|
</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