From ad2ee853311883511335b76aaa969022d3dfd607 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Fri, 17 Nov 2023 21:22:30 -0600 Subject: [PATCH] Remove generateStaticParams --- .../film/[simulation]/[photoId]/layout.tsx | 15 ------------ .../[simulation]/[photoId]/share/page.tsx | 23 +++---------------- src/app/(static)/p/[photoId]/layout.tsx | 18 ++++----------- .../shot-on/[camera]/[photoId]/layout.tsx | 18 --------------- .../shot-on/[camera]/[photoId]/share/page.tsx | 23 +++---------------- .../(static)/tag/[tag]/[photoId]/layout.tsx | 15 ------------ .../tag/[tag]/[photoId]/share/page.tsx | 23 +++---------------- 7 files changed, 14 insertions(+), 121 deletions(-) diff --git a/src/app/(static)/film/[simulation]/[photoId]/layout.tsx b/src/app/(static)/film/[simulation]/[photoId]/layout.tsx index 53b8a6d7..96546472 100644 --- a/src/app/(static)/film/[simulation]/[photoId]/layout.tsx +++ b/src/app/(static)/film/[simulation]/[photoId]/layout.tsx @@ -11,7 +11,6 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached } from '@/cache'; -import { getPhotos, getUniqueFilmSimulations } from '@/services/postgres'; import { ReactNode } from 'react'; import { FilmSimulation } from '@/simulation'; import { getPhotosFilmSimulationDataCached } from '@/simulation/data'; @@ -20,20 +19,6 @@ interface PhotoFilmSimulationProps { params: { photoId: string, simulation: FilmSimulation } } -export async function generateStaticParams() { - const params: PhotoFilmSimulationProps[] = []; - - const simulations = await getUniqueFilmSimulations(); - simulations.forEach(async ({ simulation }) => { - const photos = await getPhotos({ simulation }); - params.push(...photos.map(photo => ({ - params: { photoId: photo.id, simulation }, - }))); - }); - - return params; -} - export async function generateMetadata({ params: { photoId, simulation }, }: PhotoFilmSimulationProps): Promise { diff --git a/src/app/(static)/film/[simulation]/[photoId]/share/page.tsx b/src/app/(static)/film/[simulation]/[photoId]/share/page.tsx index 0b0b493f..782e14df 100644 --- a/src/app/(static)/film/[simulation]/[photoId]/share/page.tsx +++ b/src/app/(static)/film/[simulation]/[photoId]/share/page.tsx @@ -1,31 +1,14 @@ import { getPhotoCached } from '@/cache'; import PhotoShareModal from '@/photo/PhotoShareModal'; -import { getPhotos, getUniqueFilmSimulations } from '@/services/postgres'; import { FilmSimulation } from '@/simulation'; import { PATH_ROOT } from '@/site/paths'; import { redirect } from 'next/navigation'; -interface PhotoFilmSimulationProps { - params: { photoId: string, simulation: FilmSimulation } -} - -export async function generateStaticParams() { - const params: PhotoFilmSimulationProps[] = []; - - const simulations = await getUniqueFilmSimulations(); - simulations.forEach(async ({ simulation }) => { - const photos = await getPhotos({ simulation }); - params.push(...photos.map(photo => ({ - params: { photoId: photo.id, simulation }, - }))); - }); - - return params; -} - export default async function Share({ params: { photoId, simulation }, -}: PhotoFilmSimulationProps) { +}: { + params: { photoId: string, simulation: FilmSimulation } +}) { const photo = await getPhotoCached(photoId); if (!photo) { return redirect(PATH_ROOT); } diff --git a/src/app/(static)/p/[photoId]/layout.tsx b/src/app/(static)/p/[photoId]/layout.tsx index 834f561b..1664732b 100644 --- a/src/app/(static)/p/[photoId]/layout.tsx +++ b/src/app/(static)/p/[photoId]/layout.tsx @@ -12,20 +12,14 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached, getPhotosCached } from '@/cache'; -import { getPhotos } from '@/services/postgres'; -export async function generateStaticParams() { - const photos = await getPhotos(); - return photos.map(photo => ({ - params: { photoId: photo.id }, - })); +interface PhotoProps { + params: { photoId: string } } export async function generateMetadata({ params: { photoId }, -}: { - params: { photoId: string } -}): Promise { +}:PhotoProps): Promise { const photo = await getPhotoCached(photoId); if (!photo) { return {}; } @@ -56,10 +50,8 @@ export async function generateMetadata({ export default async function PhotoPage({ params: { photoId }, children, -}: { - params: { photoId: string } - children: React.ReactNode -}) { +}: + PhotoProps & { children: React.ReactNode }) { const photo = await getPhotoCached(photoId); if (!photo) { redirect(PATH_ROOT); } diff --git a/src/app/(static)/shot-on/[camera]/[photoId]/layout.tsx b/src/app/(static)/shot-on/[camera]/[photoId]/layout.tsx index 71f63ee0..6080421e 100644 --- a/src/app/(static)/shot-on/[camera]/[photoId]/layout.tsx +++ b/src/app/(static)/shot-on/[camera]/[photoId]/layout.tsx @@ -11,10 +11,6 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached } from '@/cache'; -import { - getPhotos, - getUniqueCameras, -} from '@/services/postgres'; import { cameraFromPhoto } from '@/camera'; import { getPhotosCameraDataCached } from '@/camera/data'; import { ReactNode } from 'react'; @@ -23,20 +19,6 @@ interface PhotoCameraProps { params: { photoId: string, camera: string } } -export async function generateStaticParams() { - const params: PhotoCameraProps[] = []; - - const cameras = await getUniqueCameras(); - cameras.forEach(async ({ cameraKey, camera }) => { - const photos = await getPhotos({ camera }); - params.push(...photos.map(photo => ({ - params: { photoId: photo.id, camera: cameraKey }, - }))); - }); - - return params; -} - export async function generateMetadata({ params: { photoId, camera }, }: PhotoCameraProps): Promise { diff --git a/src/app/(static)/shot-on/[camera]/[photoId]/share/page.tsx b/src/app/(static)/shot-on/[camera]/[photoId]/share/page.tsx index 0b3f76d8..d6bc9ec9 100644 --- a/src/app/(static)/shot-on/[camera]/[photoId]/share/page.tsx +++ b/src/app/(static)/shot-on/[camera]/[photoId]/share/page.tsx @@ -1,31 +1,14 @@ import { getPhotoCached } from '@/cache'; import { cameraFromPhoto } from '@/camera'; import PhotoShareModal from '@/photo/PhotoShareModal'; -import { getPhotos, getUniqueCameras } from '@/services/postgres'; import { PATH_ROOT } from '@/site/paths'; import { redirect } from 'next/navigation'; -interface PhotoCameraParams { - params: { photoId: string, camera: string } -} - -export async function generateStaticParams() { - const params: PhotoCameraParams[] = []; - - const cameras = await getUniqueCameras(); - cameras.forEach(async ({ cameraKey, camera }) => { - const photos = await getPhotos({ camera }); - params.push(...photos.map(photo => ({ - params: { photoId: photo.id, camera: cameraKey }, - }))); - }); - - return params; -} - export default async function Share({ params: { photoId, camera: cameraProp }, -}: PhotoCameraParams) { +}: { + params: { photoId: string, camera: string } +}) { const photo = await getPhotoCached(photoId); if (!photo) { return redirect(PATH_ROOT); } diff --git a/src/app/(static)/tag/[tag]/[photoId]/layout.tsx b/src/app/(static)/tag/[tag]/[photoId]/layout.tsx index 5e3c4e14..95403949 100644 --- a/src/app/(static)/tag/[tag]/[photoId]/layout.tsx +++ b/src/app/(static)/tag/[tag]/[photoId]/layout.tsx @@ -11,7 +11,6 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached } from '@/cache'; -import { getPhotos, getUniqueTags } from '@/services/postgres'; import { getPhotosTagDataCached } from '@/tag/data'; import { ReactNode } from 'react'; @@ -19,20 +18,6 @@ interface PhotoTagProps { params: { photoId: string, tag: string } } -export async function generateStaticParams() { - const params: PhotoTagProps[] = []; - - const tags = await getUniqueTags(); - tags.forEach(async ({ tag }) => { - const photos = await getPhotos({ tag }); - params.push(...photos.map(photo => ({ - params: { photoId: photo.id, tag }, - }))); - }); - - return params; -} - export async function generateMetadata({ params: { photoId, tag }, }: PhotoTagProps): Promise { diff --git a/src/app/(static)/tag/[tag]/[photoId]/share/page.tsx b/src/app/(static)/tag/[tag]/[photoId]/share/page.tsx index 0a892186..4ae863a0 100644 --- a/src/app/(static)/tag/[tag]/[photoId]/share/page.tsx +++ b/src/app/(static)/tag/[tag]/[photoId]/share/page.tsx @@ -1,30 +1,13 @@ import { getPhotoCached } from '@/cache'; import PhotoShareModal from '@/photo/PhotoShareModal'; -import { getPhotos, getUniqueTags } from '@/services/postgres'; import { PATH_ROOT } from '@/site/paths'; import { redirect } from 'next/navigation'; -interface PhotoTagProps { - params: { photoId: string, tag: string } -} - -export async function generateStaticParams() { - const params: PhotoTagProps[] = []; - - const tags = await getUniqueTags(); - tags.forEach(async ({ tag }) => { - const photos = await getPhotos({ tag }); - params.push(...photos.map(photo => ({ - params: { photoId: photo.id, tag }, - }))); - }); - - return params; -} - export default async function Share({ params: { photoId, tag }, -}: PhotoTagProps) { +}: { + params: { photoId: string, tag: string } +}) { const photo = await getPhotoCached(photoId); if (!photo) { return redirect(PATH_ROOT); }