'use client'; import PhotoCamera from '@/camera/PhotoCamera'; import HeaderList from '@/components/HeaderList'; import PhotoTag from '@/tag/PhotoTag'; import { PhotoDateRange, dateRangeForPhotos, photoQuantityText } from '.'; import { TAG_FAVS, TAG_HIDDEN, addHiddenToTags } from '@/tag'; import PhotoFilmSimulation from '@/simulation/PhotoFilmSimulation'; import FavsTag from '../tag/FavsTag'; import { useAppState } from '@/state/AppState'; import { useMemo, useRef } from 'react'; import HiddenTag from '@/tag/HiddenTag'; import { CATEGORY_VISIBILITY, PAGE_ABOUT } from '@/app/config'; import { htmlHasBrParagraphBreaks, safelyParseFormattedHtml, } from '@/utility/html'; import { clsx } from 'clsx/lite'; import PhotoRecipe from '@/recipe/PhotoRecipe'; import IconCamera from '@/components/icons/IconCamera'; import IconRecipe from '@/components/icons/IconRecipe'; import IconTag from '@/components/icons/IconTag'; import IconFilmSimulation from '@/components/icons/IconFilmSimulation'; import IconLens from '@/components/icons/IconLens'; import PhotoLens from '@/lens/PhotoLens'; import IconFocalLength from '@/components/icons/IconFocalLength'; import { getCategoriesWithItemsCount, PhotoSetCategories, } from '@/category'; import PhotoFocalLength from '@/focal/PhotoFocalLength'; import useElementHeight from '@/utility/useElementHeight'; const APPROXIMATE_ITEM_HEIGHT = 34; const ABOUT_HEIGHT_OFFSET = 80; export default function PhotoGridSidebar({ photosCount, photosDateRange, containerHeight, ...categories }: PhotoSetCategories & { photosCount: number photosDateRange?: PhotoDateRange containerHeight?: number }) { const { cameras, lenses, tags, simulations, recipes, focalLengths, } = categories; const categoriesCount = getCategoriesWithItemsCount( CATEGORY_VISIBILITY, categories, ); const aboutRef = useRef(null); const aboutHeight = useElementHeight(aboutRef); const height = containerHeight ? containerHeight - (aboutHeight ? aboutHeight + ABOUT_HEIGHT_OFFSET : 0) : undefined; const maxItemsPerCategory = height ? Math.max( Math.floor(height / categoriesCount / APPROXIMATE_ITEM_HEIGHT), // Always show at least 2 items 2, ) : undefined; const { start, end } = dateRangeForPhotos(undefined, photosDateRange); const { photosCountHidden } = useAppState(); const tagsIncludingHidden = useMemo(() => addHiddenToTags(tags, photosCountHidden) , [tags, photosCountHidden]); const camerasContent = cameras.length > 0 ? } maxItems={maxItemsPerCategory} items={cameras .map(({ cameraKey, camera, count }) => )} /> : null; const lensesContent = lenses.length > 0 ? } maxItems={maxItemsPerCategory} items={lenses .map(({ lensKey, lens, count }) => )} /> : null; const tagsContent = tags.length > 0 ? } maxItems={maxItemsPerCategory} items={tagsIncludingHidden .map(({ tag, count }) => { switch (tag) { case TAG_FAVS: return ; case TAG_HIDDEN: return ; default: return ; } })} /> : null; const recipesContent = recipes.length > 0 ? } maxItems={maxItemsPerCategory} items={recipes .map(({ recipe, count }) => )} /> : null; const filmsContent = simulations.length > 0 ? } maxItems={maxItemsPerCategory} items={simulations .map(({ simulation, count }) => )} /> : null; const focalLengthsContent = focalLengths.length > 0 ? } maxItems={maxItemsPerCategory} items={focalLengths.map(({ focal, count }) => )} /> : null; const photoStatsContent = photosCount > 0 ? start ? : : null; return (
{PAGE_ABOUT && ]} />} {CATEGORY_VISIBILITY.map(category => { switch (category) { case 'cameras': return camerasContent; case 'lenses': return lensesContent; case 'tags': return tagsContent; case 'recipes': return recipesContent; case 'films': return filmsContent; case 'focal-lengths': return focalLengthsContent; } })} {photoStatsContent}
); }