Skip to content

Commit

Permalink
Update async request APIs for missed pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Nov 9, 2024
1 parent 67e6793 commit 09a254b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
9 changes: 3 additions & 6 deletions app/@breadcrumbs/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import {
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb";

interface Props {
params: {
slug: string[];
};
}
type Params = Promise<{ slug: string[] }>;

interface BreadcrumbItem {
href: string;
Expand All @@ -38,7 +34,8 @@ const generateBreadcrumbs = (slug: string[]): BreadcrumbItem[] =>
isLastItem: index === slug.length - 1,
}));

const Breadcrumbs = ({ params }: Props) => {
const Breadcrumbs = async (props: { params: Params }) => {
const params = await props.params;
const breadcrumbs = generateBreadcrumbs(params.slug);

return (
Expand Down
23 changes: 14 additions & 9 deletions app/cars/fuel-types/[fuelType]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { mergeCarsByFuelType } from "@/utils/mergeCarsByFuelType";
import type { Metadata } from "next";
import type { Dataset, WithContext } from "schema-dts";

interface Props {
params: { fuelType: string };
searchParams?: { [key: string]: string };
}
type Params = Promise<{ fuelType: string }>;
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>;

export const generateMetadata = async ({
params,
searchParams,
}: Props): Promise<Metadata> => {
export const generateMetadata = async (props: {
params: Params;
searchParams: SearchParams;
}): Promise<Metadata> => {
const params = await props.params;
const searchParams = await props.searchParams;
const { fuelType } = params;
let month = searchParams?.month;

Expand Down Expand Up @@ -59,7 +59,12 @@ const fuelTypes = ["petrol", "hybrid", "electric", "diesel"];
export const generateStaticParams = () =>
fuelTypes.map((fuelType) => ({ fuelType }));

const CarsByFuelTypePage = async ({ params, searchParams }: Props) => {
const CarsByFuelTypePage = async (props: {
params: Params;
searchParams: SearchParams;
}) => {
const params = await props.params;
const searchParams = await props.searchParams;
const { fuelType } = params;

const [months, latestMonth]: [Month[], LatestMonth] = await fetchMonths();
Expand Down
20 changes: 12 additions & 8 deletions app/cars/vehicle-types/[vehicleType]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ import { mergeCarsByVehicleType } from "@/utils/mergeCarsByVehicleType";
import type { Metadata } from "next";
import type { Dataset, WithContext } from "schema-dts";

interface Props {
params: { vehicleType: string };
searchParams?: { [key: string]: string };
}
type Params = Promise<{ vehicleType: string }>;
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>;

export const generateMetadata = async ({
params,
}: Props): Promise<Metadata> => {
export const generateMetadata = async (props: {
params: Params;
}): Promise<Metadata> => {
const params = await props.params;
let { vehicleType } = params;
vehicleType = decodeURIComponent(vehicleType);
const description = `${capitaliseWords(vehicleType)} historical trends`;
Expand Down Expand Up @@ -64,7 +63,12 @@ const vehicleTypes = [
export const generateStaticParams = () =>
vehicleTypes.map((vehicleType) => ({ vehicleType }));

const CarsByVehicleTypePage = async ({ params, searchParams }: Props) => {
const CarsByVehicleTypePage = async (props: {
params: Params;
searchParams: SearchParams;
}) => {
const params = await props.params;
const searchParams = await props.searchParams;
const { vehicleType } = params;

const [months, latestMonth]: [Month[], LatestMonth] = await fetchMonths();
Expand Down

0 comments on commit 09a254b

Please sign in to comment.