Skip to content

Conversation

marjisound
Copy link
Contributor

@marjisound marjisound commented Sep 23, 2025

What does this change?

This PR introduces a new importable component, FetchMoreGalleriesData, which is responsible for fetching More Galleries data on the client side.

Updated the Placeholder component to accept a Map of heights keyed by breakpoint to account for the varying height of the More Galleries component across different screen sizes. Providing breakpoint-specific heights helps prevent layout shifts while data is loading.

The BaseTrailType is also updated with 2 new optional fields trailText & galleryCount. The relevant frontend change for this is guardian/frontend#28197

Why?

Screenshots

Before After
before after

This PR fixes #14311

@marjisound marjisound changed the base branch from main to add-more-galleries-component September 23, 2025 06:51
Copy link

github-actions bot commented Sep 23, 2025

Copy link

github-actions bot commented Sep 23, 2025

@marjisound marjisound linked an issue Sep 23, 2025 that may be closed by this pull request
@marjisound marjisound force-pushed the add-more-galleries-to-gallery-layout branch from 2141dcd to 0b0292b Compare September 24, 2025 16:58
@marjisound marjisound force-pushed the add-more-galleries-to-gallery-layout branch 4 times, most recently from 384470c to 0561643 Compare October 3, 2025 11:54
@marjisound marjisound force-pushed the add-more-galleries-to-gallery-layout branch from 9092681 to 43a5907 Compare October 6, 2025 08:46
Base automatically changed from add-more-galleries-component to main October 6, 2025 12:59
marjisound and others added 7 commits October 6, 2025 14:01
Co-authored-by: Jamie B <53781962+JamieB-gu@users.noreply.github.com>
Co-authored-by: Jamie B <53781962+JamieB-gu@users.noreply.github.com>
Removed and re-organised the styles, and shortened the components. Also
hardcoded the heading, data attributes and links because they won't
change.

Co-authored-by: Marjan Kalanaki <marjan.kalanaki@guardian.co.uk>
@marjisound marjisound force-pushed the add-more-galleries-to-gallery-layout branch from 43a5907 to 5be464d Compare October 6, 2025 13:03
@marjisound marjisound added the run_chromatic Runs chromatic when label is applied label Oct 6, 2025
@marjisound marjisound requested review from JamieB-gu and a team October 6, 2025 13:03
@marjisound marjisound marked this pull request as ready for review October 6, 2025 13:03
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Oct 6, 2025
Copy link
Contributor

@JamieB-gu JamieB-gu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a few comments.

${grid.column.centre}
color: ${palette('--caption-text')};
text-decoration: none;
align-self: start;
Copy link
Contributor

@JamieB-gu JamieB-gu Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this declaration do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the align-self: start; the <a> tag will take the entire row height which is as tall as the splash card section because by default, grid items have align-self: stretch.

This makes a big area clickable. But I thought it might be more user friendly to only have the text part clickable.

Using align-self: start; stops the anchor tag to stretch.

);

return (
<div
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we need an enclosing div, or can these styles be part of the MoreGalleries component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more galleries is using a padded grid container, so the background colour it has is not covering the whole width. This extra div ensures the background color covers the entire width of the section.

We can move this styling into the MoreGalleries container but I think but we’d likely still need a wrapper div to apply the full-width background colour. What do you think?

Comment on lines 150 to 154
addDiscussionIds(
data.trails
.map((trail) => trail.discussion?.discussionId)
.filter(isNonNullable),
);
Copy link
Contributor

@JamieB-gu JamieB-gu Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a side-effect, so it should be run inside a useEffect1. It can probably be included in the one above that's fetching the data?

Footnotes

  1. https://react.dev/learn/keeping-components-pure

if (error) {
// Send the error to Sentry and then prevent the element from rendering
window.guardian.modules.sentry.reportError(error, 'more-galleries');
return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically null is used when you want to render nothing1:

Suggested change
return undefined;
return null;

On a related note, rendering nothing here will collapse the placeholder, causing layout shift. An alternative might be to render an error state that won't cause the UI jump. Perhaps one to discuss?

Footnotes

  1. https://react.dev/learn/conditional-rendering#conditionally-returning-nothing-with-null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes lets discuss it tomorrow 👍 I've created this ticket for now #14629

const image: DCRFrontImage | undefined = trail.masterImage
? {
src: trail.masterImage,
altText: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create an issue to look into making alt text available for these images in the data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion. Created ticket in #14628

import { Placeholder } from './Placeholder';

type Props = {
limit: number; // Limit the number of items shown (the api often returns more)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a prop? If this is always "5" then we can probably hardcode that in the slice below?

marjisound and others added 2 commits October 6, 2025 16:50
Co-authored-by: Jamie B <53781962+JamieB-gu@users.noreply.github.com>
@marjisound marjisound added the run_chromatic Runs chromatic when label is applied label Oct 6, 2025
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement updated component in Gallery template
2 participants