From aabe66f202e246102e867ba2a8cb5f944bfd8d6a Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 11 Jan 2025 13:13:21 -0600 Subject: [PATCH] Refactor photo set type names --- src/camera/CameraShareModal.tsx | 7 ++----- src/focal/FocalLengthShareModal.tsx | 7 ++----- src/photo/InfinitePhotoScroll.tsx | 4 ++-- src/photo/PhotoDetailPage.tsx | 4 ++-- src/photo/PhotoGrid.tsx | 4 ++-- src/photo/PhotoHeader.tsx | 4 ++-- src/photo/PhotoLink.tsx | 4 ++-- src/photo/PhotoMedium.tsx | 4 ++-- src/photo/PhotoPrevNext.tsx | 4 ++-- src/photo/PhotoShareModal.tsx | 4 ++-- src/photo/PhotoSmall.tsx | 4 ++-- src/photo/db/index.ts | 4 ++-- src/photo/index.ts | 8 +++++++- src/simulation/FilmSimulationShareModal.tsx | 7 ++----- src/site/paths.ts | 6 +++--- src/state/AppState.ts | 5 +++-- src/tag/TagShareModal.tsx | 7 ++----- 17 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/camera/CameraShareModal.tsx b/src/camera/CameraShareModal.tsx index 3eafbe47..e8edb9fe 100644 --- a/src/camera/CameraShareModal.tsx +++ b/src/camera/CameraShareModal.tsx @@ -1,5 +1,5 @@ import { absolutePathForCamera, pathForCamera } from '@/site/paths'; -import { Photo, PhotoDateRange } from '../photo'; +import { PhotoSetAttributes } from '../photo'; import ShareModal from '@/components/ShareModal'; import CameraOGTile from './CameraOGTile'; import { Camera } from '.'; @@ -12,10 +12,7 @@ export default function CameraShareModal({ dateRange, }: { camera: Camera - photos: Photo[] - count: number - dateRange?: PhotoDateRange, -}) { +} & PhotoSetAttributes) { return ( void revalidatePhoto?: RevalidatePhoto }) => ReactNode -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const { swrTimestamp, isUserSignedIn } = useAppState(); const key = `${swrTimestamp}-${cacheKey}`; diff --git a/src/photo/PhotoDetailPage.tsx b/src/photo/PhotoDetailPage.tsx index 8f63d450..beb67cf4 100644 --- a/src/photo/PhotoDetailPage.tsx +++ b/src/photo/PhotoDetailPage.tsx @@ -1,5 +1,5 @@ import AnimateItems from '@/components/AnimateItems'; -import { Photo, PhotoDateRange, PhotoSetAttributes } from '.'; +import { Photo, PhotoDateRange, PhotoSetCategory } from '.'; import PhotoLarge from './PhotoLarge'; import SiteGrid from '@/components/SiteGrid'; import PhotoGrid from './PhotoGrid'; @@ -34,7 +34,7 @@ export default function PhotoDetailPage({ dateRange?: PhotoDateRange shouldShare?: boolean includeFavoriteInAdminMenu?: boolean -} & PhotoSetAttributes) { +} & PhotoSetCategory) { let customHeader: JSX.Element | undefined; if (tag) { diff --git a/src/photo/PhotoGrid.tsx b/src/photo/PhotoGrid.tsx index b16aea73..98e86bd5 100644 --- a/src/photo/PhotoGrid.tsx +++ b/src/photo/PhotoGrid.tsx @@ -1,6 +1,6 @@ 'use client'; -import { Photo, PhotoSetAttributes } from '.'; +import { Photo, PhotoSetCategory } from '.'; import PhotoMedium from './PhotoMedium'; import { clsx } from 'clsx/lite'; import AnimateItems from '@/components/AnimateItems'; @@ -41,7 +41,7 @@ export default function PhotoGrid({ canSelect?: boolean onLastPhotoVisible?: () => void onAnimationComplete?: () => void -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const { isUserSignedIn, selectedPhotoIds, diff --git a/src/photo/PhotoHeader.tsx b/src/photo/PhotoHeader.tsx index f66508df..7b1fdbf0 100644 --- a/src/photo/PhotoHeader.tsx +++ b/src/photo/PhotoHeader.tsx @@ -4,7 +4,7 @@ import { clsx } from 'clsx/lite'; import { Photo, PhotoDateRange, - PhotoSetAttributes, + PhotoSetCategory, dateRangeForPhotos, titleForPhoto, } from '.'; @@ -41,7 +41,7 @@ export default function PhotoHeader({ indexNumber?: number count?: number dateRange?: PhotoDateRange -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const { isGridHighDensity } = useAppState(); const { start, end } = dateRangeForPhotos(photos, dateRange); diff --git a/src/photo/PhotoLink.tsx b/src/photo/PhotoLink.tsx index 088ffc1d..72269e2b 100644 --- a/src/photo/PhotoLink.tsx +++ b/src/photo/PhotoLink.tsx @@ -1,7 +1,7 @@ 'use client'; import { ReactNode } from 'react'; -import { Photo, PhotoSetAttributes, titleForPhoto } from '@/photo'; +import { Photo, PhotoSetCategory, titleForPhoto } from '@/photo'; import Link from 'next/link'; import { AnimationConfig } from '../components/AnimateItems'; import { useAppState } from '@/state/AppState'; @@ -26,7 +26,7 @@ export default function PhotoLink({ nextPhotoAnimation?: AnimationConfig className?: string children?: ReactNode -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const { setNextPhotoAnimation } = useAppState(); return ( diff --git a/src/photo/PhotoMedium.tsx b/src/photo/PhotoMedium.tsx index df1bab48..cc1d2225 100644 --- a/src/photo/PhotoMedium.tsx +++ b/src/photo/PhotoMedium.tsx @@ -2,7 +2,7 @@ import { Photo, - PhotoSetAttributes, + PhotoSetCategory, altTextForPhoto, doesPhotoNeedBlurCompatibility, } from '.'; @@ -32,7 +32,7 @@ export default function PhotoMedium({ prefetch?: boolean className?: string onVisible?: () => void -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const ref = useRef(null); useOnVisible(ref, onVisible); diff --git a/src/photo/PhotoPrevNext.tsx b/src/photo/PhotoPrevNext.tsx index 52e8fa3d..3514c15a 100644 --- a/src/photo/PhotoPrevNext.tsx +++ b/src/photo/PhotoPrevNext.tsx @@ -3,7 +3,7 @@ import { useEffect } from 'react'; import { Photo, - PhotoSetAttributes, + PhotoSetCategory, getNextPhoto, getPreviousPhoto, } from '@/photo'; @@ -32,7 +32,7 @@ export default function PhotoPrevNext({ photo?: Photo photos?: Photo[] className?: string -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const router = useRouter(); const { diff --git a/src/photo/PhotoShareModal.tsx b/src/photo/PhotoShareModal.tsx index 8f577454..be563540 100644 --- a/src/photo/PhotoShareModal.tsx +++ b/src/photo/PhotoShareModal.tsx @@ -1,11 +1,11 @@ import PhotoOGTile from '@/photo/PhotoOGTile'; import { absolutePathForPhoto, pathForPhoto } from '@/site/paths'; -import { Photo, PhotoSetAttributes } from '.'; +import { Photo, PhotoSetCategory } from '.'; import ShareModal from '@/components/ShareModal'; export default function PhotoShareModal(props: { photo: Photo -} & PhotoSetAttributes) { +} & PhotoSetCategory) { return ( void -} & PhotoSetAttributes) { +} & PhotoSetCategory) { const ref = useRef(null); useOnVisible(ref, onVisible); diff --git a/src/photo/db/index.ts b/src/photo/db/index.ts index 63613d8a..a7a328a3 100644 --- a/src/photo/db/index.ts +++ b/src/photo/db/index.ts @@ -1,6 +1,6 @@ import { PRIORITY_ORDER_ENABLED } from '@/site/config'; import { parameterize } from '@/utility/string'; -import { PhotoSetAttributes } from '..'; +import { PhotoSetCategory } from '..'; export const GENERATE_STATIC_PARAMS_LIMIT = 1000; export const PHOTO_DEFAULT_LIMIT = 100; @@ -14,7 +14,7 @@ export type GetPhotosOptions = { takenAfterInclusive?: Date updatedBefore?: Date hidden?: 'exclude' | 'include' | 'only' -} & PhotoSetAttributes; +} & PhotoSetCategory; export const areOptionsSensitive = (options: GetPhotosOptions) => options.hidden === 'include' || options.hidden === 'only'; diff --git a/src/photo/index.ts b/src/photo/index.ts index b96abc11..5dee5ae0 100644 --- a/src/photo/index.ts +++ b/src/photo/index.ts @@ -102,7 +102,7 @@ export interface Photo extends PhotoDb { takenAtNaiveFormatted: string } -export interface PhotoSetAttributes { +export interface PhotoSetCategory { tag?: string camera?: Camera simulation?: FilmSimulation @@ -110,6 +110,12 @@ export interface PhotoSetAttributes { lens?: Lens // Unimplemented as a set } +export interface PhotoSetAttributes { + photos: Photo[] + count?: number + dateRange?: PhotoDateRange +} + export const parsePhotoFromDb = (photoDbRaw: PhotoDb): Photo => { const photoDb = camelcaseKeys( photoDbRaw as unknown as Record, diff --git a/src/simulation/FilmSimulationShareModal.tsx b/src/simulation/FilmSimulationShareModal.tsx index c0298c4b..24a92270 100644 --- a/src/simulation/FilmSimulationShareModal.tsx +++ b/src/simulation/FilmSimulationShareModal.tsx @@ -2,7 +2,7 @@ import { absolutePathForFilmSimulation, pathForFilmSimulation, } from '@/site/paths'; -import { Photo, PhotoDateRange } from '../photo'; +import { PhotoSetAttributes } from '../photo'; import ShareModal from '@/components/ShareModal'; import FilmSimulationOGTile from './FilmSimulationOGTile'; import { FilmSimulation, shareTextForFilmSimulation } from '.'; @@ -14,10 +14,7 @@ export default function FilmSimulationShareModal({ dateRange, }: { simulation: FilmSimulation - photos: Photo[] - count?: number - dateRange?: PhotoDateRange -}) { +} & PhotoSetAttributes) { return ( export const getPathComponents = (pathname = ''): { photoId?: string -} & PhotoSetAttributes => { +} & PhotoSetCategory => { const photoIdFromPhoto = pathname.match( new RegExp(`^${PREFIX_PHOTO}/([^/]+)`))?.[1]; const photoIdFromTag = pathname.match( diff --git a/src/state/AppState.ts b/src/state/AppState.ts index 0d309611..2ccd7675 100644 --- a/src/state/AppState.ts +++ b/src/state/AppState.ts @@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, createContext, useContext } from 'react'; import { AnimationConfig } from '@/components/AnimateItems'; export interface AppStateContext { - // CORE + // GLOBAL previousPathname?: string hasLoaded?: boolean setHasLoaded?: Dispatch> @@ -13,9 +13,10 @@ export interface AppStateContext { clearNextPhotoAnimation?: () => void shouldRespondToKeyboardCommands?: boolean setShouldRespondToKeyboardCommands?: Dispatch> + // MODAL isCommandKOpen?: boolean setIsCommandKOpen?: Dispatch> - // ADMIN + // ADMIN userEmail?: string setUserEmail?: Dispatch> isUserSignedIn?: boolean diff --git a/src/tag/TagShareModal.tsx b/src/tag/TagShareModal.tsx index 359ac41e..8bf78f46 100644 --- a/src/tag/TagShareModal.tsx +++ b/src/tag/TagShareModal.tsx @@ -1,5 +1,5 @@ import { absolutePathForTag, pathForTag } from '@/site/paths'; -import { Photo, PhotoDateRange } from '../photo'; +import { PhotoSetAttributes } from '../photo'; import ShareModal from '@/components/ShareModal'; import TagOGTile from './TagOGTile'; import { shareTextForTag } from '.'; @@ -11,10 +11,7 @@ export default function TagShareModal({ dateRange, }: { tag: string - photos: Photo[] - count?: number - dateRange?: PhotoDateRange -}) { +} & PhotoSetAttributes) { return (