From 19965a1aea36fd53f4b801d69b42ff4c96468788 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 18 Jan 2024 14:50:59 -0600 Subject: [PATCH] Remove search params from /grid --- src/app/grid/page.tsx | 33 ++++--- src/app/page.tsx | 15 +-- src/photo/MorePhotosGrid.tsx | 42 +++++++++ ...MorePhotosLarge.tsx => MorePhotosRoot.tsx} | 4 +- src/photo/PhotoGrid.tsx | 93 +++++++++---------- src/photo/index.ts | 5 +- src/state/MoreComponentsState.ts | 6 +- 7 files changed, 121 insertions(+), 77 deletions(-) create mode 100644 src/photo/MorePhotosGrid.tsx rename src/photo/{MorePhotosLarge.tsx => MorePhotosRoot.tsx} (94%) diff --git a/src/app/grid/page.tsx b/src/app/grid/page.tsx index f58784a1..9b2b4a6c 100644 --- a/src/app/grid/page.tsx +++ b/src/app/grid/page.tsx @@ -1,26 +1,24 @@ import { getPhotosCached } from '@/cache'; import SiteGrid from '@/components/SiteGrid'; -import { generateOgImageMetaForPhotos } from '@/photo'; +import { + PHOTO_LOAD_MULTIPLE_GRID, + generateOgImageMetaForPhotos, +} from '@/photo'; import PhotoGrid from '@/photo/PhotoGrid'; import PhotosEmptyState from '@/photo/PhotosEmptyState'; import { MAX_PHOTOS_TO_SHOW_OG } from '@/photo/image-response'; -import { pathForGrid } from '@/site/paths'; import { Metadata } from 'next/types'; -import { - PaginationParams, - getPaginationForSearchParams, -} from '@/site/pagination'; import PhotoGridSidebar from '@/photo/PhotoGridSidebar'; import { getPhotoSidebarDataCached } from '@/photo/data'; +import { MorePhotosGrid } from '@/photo/MorePhotosGrid'; +import { Suspense } from 'react'; export async function generateMetadata(): Promise { const photos = await getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG }); return generateOgImageMetaForPhotos(photos); } -export default async function GridPage({ searchParams }: PaginationParams) { - const { offset, limit } = getPaginationForSearchParams(searchParams); - +export default async function GridPage() { const [ photos, photosCount, @@ -28,18 +26,23 @@ export default async function GridPage({ searchParams }: PaginationParams) { cameras, simulations, ] = await Promise.all([ - getPhotosCached({ limit }), + getPhotosCached({ limit: PHOTO_LOAD_MULTIPLE_GRID }), ...getPhotoSidebarDataCached(), ]); - const showMorePath = photosCount > photos.length - ? pathForGrid(offset + 1) - : undefined; - return ( photos.length > 0 ? } + contentMain={
+ + + + +
} contentSide={
[]), + getPhotosCached({ limit: PHOTO_LOAD_MULTIPLE_ROOT }).catch(() => []), getPhotosCountCached().catch(() => 0), ]); @@ -31,9 +34,9 @@ export default async function HomePage() { ?
- diff --git a/src/photo/MorePhotosGrid.tsx b/src/photo/MorePhotosGrid.tsx new file mode 100644 index 00000000..dd59ba57 --- /dev/null +++ b/src/photo/MorePhotosGrid.tsx @@ -0,0 +1,42 @@ +import MoreComponents from '@/components/MoreComponents'; +import { getPhotosCached } from '@/cache'; +import PhotoGrid from './PhotoGrid'; + +export function MorePhotosGrid({ + initialOffset, + itemsPerRequest, + totalPhotosCount, +}: { + initialOffset: number + itemsPerRequest: number + totalPhotosCount: number +}) { + return ( + { + 'use server'; + if ( + process.env.NODE_ENV === 'development' && + Math.random() < 0.95 + ) { + return { didFail: true }; + } + const photos = await getPhotosCached({ limit: offset + limit }) + .catch(() => undefined); + if (!photos) { + return { didFail: true }; + } else { + const nextPhotos = photos.slice(offset); + return { + nextComponent: , + isFinished: offset + limit >= totalPhotosCount, + }; + } + }} + /> + ); +} diff --git a/src/photo/MorePhotosLarge.tsx b/src/photo/MorePhotosRoot.tsx similarity index 94% rename from src/photo/MorePhotosLarge.tsx rename to src/photo/MorePhotosRoot.tsx index 491975e5..6f8a7c53 100644 --- a/src/photo/MorePhotosLarge.tsx +++ b/src/photo/MorePhotosRoot.tsx @@ -2,7 +2,7 @@ import MoreComponents from '@/components/MoreComponents'; import PhotosLarge from './PhotosLarge'; import { getPhotosCached } from '@/cache'; -export function MorePhotosLarge({ +export function MorePhotosRoot({ initialOffset, itemsPerRequest, totalPhotosCount, @@ -13,7 +13,7 @@ export function MorePhotosLarge({ }) { return ( - -
*]:flex [&>*]:w-full [&>*]:h-full', - '[&>*>*]:object-cover [&>*>*]:min-h-full', - ) - : undefined} - style={{ - ...GRID_ASPECT_RATIO !== 0 && { - aspectRatio: GRID_ASPECT_RATIO, - }, - }} - > - -
).concat(additionalTile ?? [])} - /> - {showMorePath && - } -
+ +
*]:flex [&>*]:w-full [&>*]:h-full', + '[&>*>*]:object-cover [&>*>*]:min-h-full', + ) + : undefined} + style={{ + ...GRID_ASPECT_RATIO !== 0 && { + aspectRatio: GRID_ASPECT_RATIO, + }, + }} + > + +
).concat(additionalTile ?? [])} + /> ); }; diff --git a/src/photo/index.ts b/src/photo/index.ts index a49e3751..d7ef8979 100644 --- a/src/photo/index.ts +++ b/src/photo/index.ts @@ -11,8 +11,11 @@ import { import camelcaseKeys from 'camelcase-keys'; import type { Metadata } from 'next'; -export const LARGE_PHOTOS_TO_SHOW = +export const PHOTO_LOAD_MULTIPLE_ROOT = process.env.NODE_ENV === 'development' ? 2 : 12; +export const PHOTO_LOAD_MULTIPLE_GRID = + process.env.NODE_ENV === 'development' ? 4 : 24; + export const GRID_THUMBNAILS_TO_SHOW_MAX = 12; export const ACCEPTED_PHOTO_FILE_TYPES = [ diff --git a/src/state/MoreComponentsState.ts b/src/state/MoreComponentsState.ts index 78b07d4f..d4cccb04 100644 --- a/src/state/MoreComponentsState.ts +++ b/src/state/MoreComponentsState.ts @@ -1,7 +1,8 @@ import { createContext, useContext } from 'react'; export type MoreComponentsKey = - 'PhotosLarge'; + 'PhotosRoot' | + 'PhotosGrid'; export interface MoreComponentsStateForKey { indexToView: number @@ -39,7 +40,8 @@ export interface MoreComponentsContext { } export const MORE_COMPONENTS_INITIAL_STATE: MoreComponentsState = { - PhotosLarge: createInitialStateForKey(), + PhotosRoot: createInitialStateForKey(), + PhotosGrid: createInitialStateForKey(), }; export const MoreComponentsContext =