Shares the Instagram block between pages

Moves InstagramGrid out of the homepage sections and gives it its own
content module, so the portfolio can show the same block. The homepage
renders exactly as before; the tiles keep reusing the intro and review
photos, so each photo keeps one description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 21:32:48 +01:00
co-authored by Claude Opus 5.5
parent b35b1c2404
commit e013f1436b
13 changed files with 394 additions and 31 deletions
@@ -1,66 +0,0 @@
import { screen, within } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import homeContent from '@/content/homeContent';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import InstagramGrid from './InstagramGrid';
const instagram = homeContent.instagram;
const PROFILE = 'https://www.instagram.com/andreaslopfotografie/';
function expectExternal(link: HTMLElement) {
expect(link).toHaveAttribute('href', PROFILE);
expect(link).toHaveAttribute('target', '_blank');
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
}
describe('InstagramGrid', () => {
it('shows the heading and the handle as a link to the profile', async () => {
const { container } = await renderWithProviders(
<InstagramGrid content={instagram} profileUrl={PROFILE} />,
);
const section = screen.getByRole('region', { name: 'Instagram' });
expect(
within(section).getByRole('heading', { level: 2 }),
).toHaveTextContent('Instagram');
const handle = screen.getByTestId('instagram-handle-link');
expect(handle).toHaveAccessibleName(
'@andreaslopfotografie (opent in nieuw tabblad)',
);
expectExternal(handle);
expect(await axeResults(container)).toHaveNoViolations();
});
it('shows six photo tiles in order, each linking to the profile', async () => {
await renderWithProviders(
<InstagramGrid content={instagram} profileUrl={PROFILE} />,
);
const items = within(screen.getByRole('list')).getAllByRole('listitem');
expect(items).toHaveLength(6);
instagram.photos.forEach((photo, index) => {
const tile = screen.getByTestId(`instagram-tile-${index + 1}`);
expect(items[index]).toContainElement(tile);
expectExternal(tile);
expect(tile).toHaveAccessibleName(
`${photo.alt} (Instagram, opent in nieuw tabblad)`,
);
const image = within(tile).getByRole('img');
expect(image).toHaveAttribute('loading', 'lazy');
expect(image).toHaveAttribute('width', String(photo.width));
});
});
it('still renders the heading and handle when there are no photos', async () => {
await renderWithProviders(
<InstagramGrid
content={{ ...instagram, photos: [] }}
profileUrl={PROFILE}
/>,
);
expect(
screen.getByRole('heading', { name: 'Instagram' }),
).toBeInTheDocument();
expect(screen.getByTestId('instagram-handle-link')).toBeInTheDocument();
expect(screen.queryAllByRole('img')).toHaveLength(0);
});
});
@@ -1,117 +0,0 @@
import { Box, chakra, Container, Link, VisuallyHidden } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent } from '@/content/types';
const TITLE_ID = 'instagram-title';
type InstagramGridProps = {
content: HomeContent['instagram'];
// A checked https link (visibleSocials); without one the route leaves
// the section out
profileUrl: string;
};
// "Instagram" (design .instagram): the handle as a link to the profile and
// a row of square photos running from edge to edge, each linking to the
// profile too. A fixed selection until the API delivers the real feed.
export default function InstagramGrid({
content,
profileUrl,
}: InstagramGridProps) {
return (
<PageSection
labelledBy={TITLE_ID}
spacing="tight"
width="full"
data-testid="instagram-grid"
>
<Container maxW="content">
<Reveal>
<SectionHeading
id={TITLE_ID}
title={content.title}
lead={
<Link
variant="underline"
href={profileUrl}
target="_blank"
rel="noopener noreferrer"
data-testid="instagram-handle-link"
>
{/* Space outside the hidden text, or it drops
out of the announced name */}
{content.handle}{' '}
<VisuallyHidden>
(opent in nieuw tabblad)
</VisuallyHidden>
</Link>
}
/>
</Reveal>
</Container>
<Reveal>
{/* The design's 680px and 1100px steps on the theme breakpoints */}
<chakra.ul
listStyleType="none"
display="grid"
gridTemplateColumns={{
base: 'repeat(2, 1fr)',
md: 'repeat(3, 1fr)',
xl: 'repeat(6, 1fr)',
}}
gap="2px"
>
{content.photos.map((photo, i) => (
// The same photo may appear twice in a feed
<chakra.li key={`${i}-${photo.src}`}>
<chakra.a
href={profileUrl}
target="_blank"
rel="noopener noreferrer"
data-testid={`instagram-tile-${i + 1}`}
display="block"
position="relative"
// Keeps the focus ring above the neighbouring
// tiles, which sit only 2px away
_focusVisible={{ zIndex: 1 }}
className="group"
>
<Box overflow="hidden" bg="paper.deep">
<DeferredImage
image={photo}
w="100%"
aspectRatio="1 / 1"
objectFit="cover"
transitionProperty="transform, opacity"
transitionDuration="interaction"
transitionTimingFunction="smooth"
_groupHover={{
transform: 'scale(1.06)',
opacity: 0.85,
}}
_groupFocusVisible={{
transform: 'scale(1.06)',
opacity: 0.85,
}}
// Only the fade, no zoom
_motionReduce={{
transform: 'none !important',
}}
/>
</Box>
{/* The photo's alt names the link; this says
where it goes */}{' '}
<VisuallyHidden>
(Instagram, opent in nieuw tabblad)
</VisuallyHidden>
</chakra.a>
</chakra.li>
))}
</chakra.ul>
</Reveal>
</PageSection>
);
}