Skip to content

Commit

Permalink
feat: gallery route structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff committed Dec 27, 2024
1 parent fec1596 commit e033a1f
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
12 changes: 7 additions & 5 deletions app/[locale]/[...uriSegments]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const pickFeaturedImage = async (
};

export async function generateMetadata(
{ params: { locale, uriSegments }, searchParams = {} }: UriSegmentProps,
{
params: { locale, uriSegments },
searchParams = {},
}: WithSearchParams<UriSegmentProps>,
parent: ResolvingMetadata
): Promise<Metadata> {
const uri = uriSegments.join("/");
Expand Down Expand Up @@ -109,10 +112,9 @@ const sectionMap = {
staffProfiles: StaffPageTemplate,
};

const UriSegmentsPage: FunctionComponent<UriSegmentProps> = async ({
params: { locale, uriSegments },
searchParams,
}) => {
const UriSegmentsPage: FunctionComponent<
WithSearchParams<UriSegmentProps>
> = async ({ params: { locale, uriSegments }, searchParams }) => {
const uri = uriSegments.join("/");
let previewToken: string | undefined;

Expand Down
14 changes: 14 additions & 0 deletions app/[locale]/gallery/[gallery]/[image]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FunctionComponent } from "react";

const GalleryImage: FunctionComponent<WithSearchParams<GalleryImageProps>> = ({
params: { locale, gallery, image },
searchParams = {},
}) => {
return (
<div>
<h1>Image {image}</h1>
</div>
);
};

export default GalleryImage;
20 changes: 20 additions & 0 deletions app/[locale]/gallery/[gallery]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { FunctionComponent } from "react";

// should retrieve all galleries by entry, and
// return an array of their slugs to statically
// generate their content
// export async function generateStaticParams() {
// }

const Gallery: FunctionComponent<WithSearchParams<GalleryProps>> = ({
params: { locale, gallery },
searchParams = {},
}) => {
return (
<div>
<h1>Gallery {gallery}</h1>
</div>
);
};

export default Gallery;
14 changes: 14 additions & 0 deletions app/[locale]/gallery/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FunctionComponent } from "react";

const GalleryLanding: FunctionComponent<WithSearchParams<LocaleProps>> = ({
params: { locale },
searchParams = {},
}) => {
return (
<div>
<h1>Gallery Landing</h1>
</div>
);
};

export default GalleryLanding;
4 changes: 2 additions & 2 deletions app/[locale]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import HomePageTemplate from "@/templates/HomePage";
export async function generateMetadata({
params: { locale },
searchParams = {},
}: LocaleProps): Promise<Metadata> {
}: WithSearchParams<LocaleProps>): Promise<Metadata> {
let previewToken: string | undefined;

if (draftMode().isEnabled) {
Expand All @@ -24,7 +24,7 @@ export async function generateMetadata({
return { title, description };
}

const RootPage: FunctionComponent<LocaleProps> = async ({
const RootPage: FunctionComponent<WithSearchParams<LocaleProps>> = async ({
params: { locale },
searchParams = {},
}) => {
Expand Down
29 changes: 27 additions & 2 deletions types/next.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
type SearchParams = Record<string, string | Array<string> | undefined>;

/** Layout components cannot access search params, so route segment
* props should be extended for Page components with this helper.
*/
type WithSearchParams<T = unknown> = T & {
/** An object containing the search parameters of the current URL
* @link https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional
*/
searchParams?: SearchParams;
};

type LocaleParams = {
locale: string;
};
Expand All @@ -7,14 +18,28 @@ type UriSegmentParams = {
uriSegments: Array<string>;
};

type GalleryParams = {
gallery: string;
};

type GalleryImageParams = {
image: string;
};

interface LocaleProps {
params: LocaleParams;
searchParams?: SearchParams;
}

interface UriSegmentProps {
params: LocaleParams & UriSegmentParams;
searchParams: SearchParams;
}

interface GalleryProps {
params: LocaleParams & GalleryParams;
}

interface GalleryImageProps {
params: LocaleParams & GalleryParams & GalleryImageParams;
}

interface ErrorProps {
Expand Down

0 comments on commit e033a1f

Please sign in to comment.