Reveal content is visible in the HTML and only content below the viewport hides after hydration. Deferred photos get a noscript twin, and the first row of the portfolio loads eagerly per column count. Some old tests still expect the former behaviour; they are rewritten next, so this commit's test run is not fully green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.8 KiB
TypeScript
100 lines
3.8 KiB
TypeScript
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
|
import InstagramGrid from '../components/InstagramGrid/InstagramGrid';
|
|
import PageIntro from '../components/PageIntro/PageIntro';
|
|
import PortfolioGallery from '../components/portfolio/PortfolioGallery/PortfolioGallery';
|
|
import instagramContent from '../content/instagramContent';
|
|
import portfolioContent from '../content/portfolioContent';
|
|
import shootTypes from '../content/shootTypes';
|
|
import siteContent from '../content/siteContent';
|
|
import type { ShootTypeId } from '../content/types';
|
|
import { firstRowPreloads } from '../lib/firstRow';
|
|
import {
|
|
filterPhotos,
|
|
isShootTypeId,
|
|
toGalleryItems,
|
|
} from '../lib/portfolioFilters';
|
|
import { visibleSocials } from '../lib/visibleSocials';
|
|
import useHydrated from '../hooks/useHydrated';
|
|
import { galleryImages, pageHead, structuredDataScript, webPage } from '../seo';
|
|
|
|
// ?shoot= from a filter or a "Bekijk meer …foto's" link: only a known shoot
|
|
// type is kept, so links to it are type-checked (BR-SP-01). Whether that
|
|
// type has photos is checked on the page.
|
|
type PortfolioSearch = { shoot?: ShootTypeId };
|
|
|
|
const shootTypeIds = shootTypes.map((type) => type.id);
|
|
|
|
export const Route = createFileRoute('/portfolio')({
|
|
validateSearch: (search: Record<string, unknown>): PortfolioSearch => {
|
|
const value =
|
|
typeof search.shoot === 'string'
|
|
? search.shoot.trim().toLowerCase()
|
|
: undefined;
|
|
return isShootTypeId(value, shootTypeIds) ? { shoot: value } : {};
|
|
},
|
|
head: () => {
|
|
const base = pageHead('/portfolio');
|
|
// The unfiltered list the page renders: ?shoot= only applies after
|
|
// hydration
|
|
const items = toGalleryItems(
|
|
filterPhotos(portfolioContent.photos, undefined),
|
|
shootTypes,
|
|
);
|
|
return {
|
|
...base,
|
|
links: [...base.links, ...firstRowPreloads(items)],
|
|
scripts: [
|
|
structuredDataScript(
|
|
webPage('ImageGallery', '/portfolio', {
|
|
associatedMedia: galleryImages(portfolioContent.photos),
|
|
}),
|
|
),
|
|
],
|
|
};
|
|
},
|
|
component: Portfolio,
|
|
});
|
|
|
|
// The portfolio (LAYOUT.md: Intro → Portfolio → Instagram): the photos with
|
|
// filters and lightbox, then the same Instagram block as on the homepage
|
|
function Portfolio() {
|
|
const { shoot: searched } = Route.useSearch();
|
|
// The filter only applies after hydration, so the prerendered HTML and the
|
|
// first browser render agree (BR-HYD-10)
|
|
const shoot = useHydrated() ? searched : undefined;
|
|
const navigate = useNavigate({ from: Route.fullPath });
|
|
const { intro, photos } = portfolioContent;
|
|
// Without a valid https link the tiles would lead nowhere: no section
|
|
const instagram = visibleSocials(siteContent.socials).find(
|
|
(social) => social.platform === 'instagram',
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<PageIntro eyebrow={intro.eyebrow} title={intro.title}>
|
|
{intro.text}
|
|
</PageIntro>
|
|
<PortfolioGallery
|
|
photos={photos}
|
|
shootTypes={shootTypes}
|
|
shoot={shoot}
|
|
// The filter is a view, not a step: no history entry per
|
|
// change and no jump to the top (application design Q4)
|
|
onShootChange={(next) =>
|
|
navigate({
|
|
search: next ? { shoot: next } : {},
|
|
replace: true,
|
|
resetScroll: false,
|
|
})
|
|
}
|
|
/>
|
|
{instagram && (
|
|
<InstagramGrid
|
|
content={instagramContent}
|
|
profileUrl={instagram.href}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
}
|