Skip to content

Commit

Permalink
Make isFirstFeaturedTextSlice variable(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpmccormick committed Apr 10, 2024
1 parent 0d1372e commit 5e06522
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions content/webapp/components/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,34 +172,29 @@ const Body: FunctionComponent<Props> = ({
comicPreviousNext,
contentType,
}: Props) => {
const isFirstFeaturedTextSliceFromBody = (slice, i) =>
i === 0 && slice.type === 'text' && slice.weight === 'featured';
const isFirstFeaturedTextSliceFromUntransformedBody = (slice, i) =>
i === 0 && slice.slice_type === 'text' && slice.slice_label === 'featured';

const { sliceMachine } = useToggles();
const featuredTextFromBody = body.find(
(slice, i) =>
i === 0 && slice.type === 'text' && slice.weight === 'featured'
isFirstFeaturedTextSliceFromBody
) as Slice<'text', prismic.RichTextField>;
const featuredTextFromUntransformedBody = untransformedBody.find(
(slice, i) =>
i === 0 && slice.slice_type === 'text' && slice.slice_label === 'featured'
isFirstFeaturedTextSliceFromUntransformedBody
) as prismic.Slice<'text', { text: prismic.RichTextField }>;

const filteredBody = body
.filter(
(slice, i) =>
!(i === 0 && slice.type === 'text' && slice.weight === 'featured')
)
.filter((slice, i) => !isFirstFeaturedTextSliceFromBody(slice, i))
.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'
)
(slice, i) => !isFirstFeaturedTextSliceFromUntransformedBody(slice, i)
)
.filter(
slice =>
Expand Down

0 comments on commit 5e06522

Please sign in to comment.