From b32243e2991003628cbfbf72bb57f96454b6da5d Mon Sep 17 00:00:00 2001 From: davidpmccormick Date: Tue, 9 Apr 2024 16:00:55 +0100 Subject: [PATCH 1/4] Move 'FeaturedText' out of the body map --- content/webapp/components/Body/Body.tsx | 516 ++++++++++++------------ 1 file changed, 266 insertions(+), 250 deletions(-) diff --git a/content/webapp/components/Body/Body.tsx b/content/webapp/components/Body/Body.tsx index 1dc52aa42e..c9cdc2e573 100644 --- a/content/webapp/components/Body/Body.tsx +++ b/content/webapp/components/Body/Body.tsx @@ -57,6 +57,7 @@ import TextAndImageOrIcons from '../TextAndImageOrIcons'; import { SliceZone } from '@prismicio/react'; import { components } from '@weco/common/views/slices'; import { useToggles } from '@weco/common/server-data/Context'; +import { Slice } from '@weco/content/types/body'; const BodyWrapper = styled.div<{ $splitBackground: boolean }>` ${props => @@ -172,13 +173,34 @@ const Body: FunctionComponent = ({ contentType, }: Props) => { const { sliceMachine } = useToggles(); + const featuredTextFromBody = body.find( + (slice, i) => + i === 0 && slice.type === 'text' && slice.weight === 'featured' + ) as Slice<'text', prismic.RichTextField>; + const featuredTextFromUntransformedBody = untransformedBody.find( + (slice, i) => + i === 0 && slice.slice_type === 'text' && slice.slice_label === 'featured' + ) as prismic.Slice<'text', { text: prismic.RichTextField }>; + const filteredBody = body + .filter( + (slice, i) => + !(i === 0 && slice.type === 'text' && slice.weight === 'featured') + ) .filter(slice => !(slice.type === 'picture' && slice.weight === 'featured')) // The standfirst is now put into the header // and used exclusively by articles / article series .filter(slice => slice.type !== 'standfirst'); const filteredUntransformedBody = untransformedBody + .filter( + (slice, i) => + !( + i === 0 && + slice.slice_type === 'text' && + slice.slice_label === 'featured' + ) + ) .filter( slice => !( @@ -345,6 +367,28 @@ const Body: FunctionComponent = ({ className={`content-type-${contentType}`} $splitBackground={isShortFilm} > + {featuredTextFromBody && featuredTextFromUntransformedBody && ( + +
+ + + +
+
+ )} + {filteredBody.length < 1 && ( = ({ filteredBody.map((slice, i) => ( {/* If the first slice is featured text we display it and any static content, i.e. */} - {i === 0 && - slice.type === 'text' && - slice.weight === 'featured' && ( - -
- - - -
-
- )} - {!( - i === 0 && - slice.type === 'text' && - slice.weight === 'featured' - ) && ( - <> - {slice.type === 'text' && ( - - -
- {slice.weight !== 'featured' && - (firstTextSliceIndex === i && isDropCapped ? ( - <> - {/* + + {slice.type === 'text' && ( + + +
+ {slice.weight !== 'featured' && + (firstTextSliceIndex === i && isDropCapped ? ( + <> + {/* The featured text slice can contain multiple paragraphs, e.g. https://wellcomecollection.org/articles/XcMBBREAACUAtBoV The drop cap serializer will see them as two separate paragraphs, so we have to split out the first paragraph here. */} - - - - ) : ( - - ))} -
-
-
- )} + + + + ) : ( + + ))} +
+
+
+ )} - {slice.type === 'textAndImage' && ( - - - - - - )} + {slice.type === 'textAndImage' && ( + + + + + + )} - {slice.type === 'textAndIcons' && ( - - - - - - )} + {slice.type === 'textAndIcons' && ( + + + + + + )} - {/* TODO: use one layout for all image weights if/when it's established + {/* TODO: use one layout for all image weights if/when it's established that width isn't an adequate means to illustrate a difference */} - {slice.type === 'picture' && slice.weight === 'default' && ( - - - - - - )} - {slice.type === 'picture' && slice.weight === 'standalone' && ( - - - - - - )} - {slice.type === 'picture' && slice.weight === 'supporting' && ( - - - - - - )} - {slice.type === 'imageGallery' && ( - - + + + + + )} + {slice.type === 'picture' && slice.weight === 'standalone' && ( + + + + + + )} + {slice.type === 'picture' && slice.weight === 'supporting' && ( + + + + + + )} + {slice.type === 'imageGallery' && ( + + + + )} + {slice.type === 'quote' && ( + + + + + + )} + {slice.type === 'titledTextList' && ( + + + + + + )} + {slice.type === 'contentList' && !isLanding && ( + + + {/* FIXME: this makes what-we-do contentLists synchronous, but it's hacky. */} + {pageId === prismicPageIds.whatWeDo ? ( + - - )} - {slice.type === 'quote' && ( - - - - - - )} - {slice.type === 'titledTextList' && ( - - - - - - )} - {slice.type === 'contentList' && !isLanding && ( - - - {/* FIXME: this makes what-we-do contentLists synchronous, but it's hacky. */} - {pageId === prismicPageIds.whatWeDo ? ( - - ) : ( - - 'id' in item ? `id:${item.id}` : undefined - ) - .filter(isNotUndefined) - .join(' ')} - /> - )} - - - )} - {slice.type === 'searchResults' && ( - - - - - - )} - {slice.type === 'videoEmbed' && ( - - - - - - )} - {slice.type === 'soundcloudEmbed' && ( - - - - - - )} - {slice.type === 'map' && ( - - - - - - )} - {slice.type === 'gifVideo' && ( - - - - - - )} - {slice.type === 'iframe' && ( - - -