Skip to content

Commit eabfa94

Browse files
authored
Merge pull request #1328 from prezly/feature/dev-20811-brussels-airlines-wants-to-remove-latest-stories-title-from
[DEV-20811] Fix - Hide "Latest stories" H1 on homepage in certain conditions
2 parents 21d649e + 6bab906 commit eabfa94

File tree

11 files changed

+65
-44
lines changed

11 files changed

+65
-44
lines changed

app/[localeCode]/(story)/[slug]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function generateMetadata({ params }: Props) {
3737
}
3838

3939
export default async function StoryPage(props: Props) {
40+
const { localeCode } = await props.params;
4041
const searchParams = await props.searchParams;
4142
const { story, relatedStories } = await resolve(props.params);
4243
const settings = await app().themeSettings();
@@ -61,6 +62,7 @@ export default async function StoryPage(props: Props) {
6162
sharing_actions: themeSettings.sharing_actions,
6263
}}
6364
withBadges={themeSettings.story_card_variant === 'boxed'}
65+
locale={localeCode}
6466
/>
6567
</>
6668
);

app/[localeCode]/(story)/preview/[uuid]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function generateMetadata(props: Props) {
4343
}
4444

4545
export default async function PreviewStoryPage(props: Props) {
46+
const { localeCode } = await props.params;
4647
const searchParams = await props.searchParams;
4748
const { story, relatedStories } = await resolve(props.params);
4849
const settings = await app().themeSettings();
@@ -67,6 +68,7 @@ export default async function PreviewStoryPage(props: Props) {
6768
sharing_actions: [], // Cannot share unpublished article
6869
}}
6970
withBadges={themeSettings.story_card_variant === 'boxed'}
71+
locale={localeCode}
7072
/>
7173
</>
7274
);

app/[localeCode]/(story)/secret/[uuid]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function generateMetadata(props: Props) {
3737
}
3838

3939
export default async function SecretStoryPage(props: Props) {
40+
const { localeCode } = await props.params;
4041
const searchParams = await props.searchParams;
4142
const { story, relatedStories } = await resolve(props.params);
4243
const settings = await app().themeSettings();
@@ -61,6 +62,7 @@ export default async function SecretStoryPage(props: Props) {
6162
sharing_actions: themeSettings.sharing_actions,
6263
}}
6364
withBadges={themeSettings.story_card_variant === 'boxed'}
65+
locale={localeCode}
6466
/>
6567
</>
6668
);

src/modules/InfiniteHubStories/InfiniteHubStories.module.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
display: grid;
33
gap: $spacing-4;
44
grid-template-columns: repeat(2, 1fr);
5-
margin-bottom: $spacing-10;
5+
6+
&.withMargin {
7+
margin-bottom: $spacing-10;
8+
}
69

710
@include tablet-up {
811
&.four {

src/modules/InfiniteHubStories/InfiniteHubStories.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ export function InfiniteHubStories({
5454
const locale = useLocale();
5555
const includedNewsrooms = newsrooms.filter(({ uuid }) => uuid !== newsroomUuid);
5656

57-
const { load, loading, data, done } = useInfiniteLoading(
57+
const {
58+
load,
59+
loading,
60+
data: stories,
61+
done,
62+
} = useInfiniteLoading(
5863
useCallback(
5964
(offset) =>
6065
fetchStories({
@@ -93,7 +98,11 @@ export function InfiniteHubStories({
9398

9499
return (
95100
<div>
96-
<div className={classNames(styles.newsrooms, getColumnsClassName())}>
101+
<div
102+
className={classNames(styles.newsrooms, getColumnsClassName(), {
103+
[styles.withMargin]: stories.length > 0,
104+
})}
105+
>
97106
{includedNewsrooms.map((newsroom) => (
98107
<NewsroomLogo key={newsroom.uuid} newsroom={newsroom} />
99108
))}
@@ -107,7 +116,7 @@ export function InfiniteHubStories({
107116
newsroomUuid={newsroomUuid}
108117
showDate={showDate}
109118
showSubtitle={showSubtitle}
110-
stories={data}
119+
stories={stories}
111120
storyCardVariant={storyCardVariant}
112121
withEmptyState={false}
113122
/>

src/modules/InfiniteStories/StoriesList.module.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
.filtersContainer {
1+
.pageTitle {
2+
margin-bottom: $spacing-5 !important;
3+
4+
&.aria {
5+
@include sr-only;
6+
}
7+
}
8+
9+
.filters {
210
margin-bottom: $spacing-7;
311
}
412

src/modules/InfiniteStories/StoriesList.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import type { Newsroom } from '@prezly/sdk';
44
import { Category } from '@prezly/sdk';
5-
import { translations } from '@prezly/theme-kit-nextjs';
5+
import { translations, useIntl } from '@prezly/theme-kit-nextjs';
66
import classNames from 'classnames';
77
import { useMemo } from 'react';
88

99
import { FormattedMessage, useLocale } from '@/adapters/client';
10+
import { PageTitle } from '@/components/PageTitle';
1011
import { StaggeredLayout } from '@/components/StaggeredLayout';
1112
import { HighlightedStoryCard, StoryCard } from '@/components/StoryCards';
1213
import type { ThemeSettings } from '@/theme-settings';
@@ -52,7 +53,9 @@ export function StoriesList({
5253
withEmptyState = true,
5354
}: Props) {
5455
const locale = useLocale();
56+
const { formatMessage } = useIntl();
5557
const hasCategories = categories.length > 0;
58+
const hasStories = stories.length > 0;
5659

5760
const [highlightedStories, restStories] = useMemo(() => {
5861
if (isCategoryList) {
@@ -110,13 +113,22 @@ export function StoriesList({
110113
})}
111114
</div>
112115
)}
113-
<CategoriesFilters
114-
activeCategory={category}
115-
categories={categories}
116-
className={styles.filtersContainer}
117-
hasStories={stories.length > 0}
118-
locale={locale}
116+
<PageTitle
117+
className={classNames(styles.pageTitle, {
118+
// We want to hide the page title for regular users, but keep it
119+
// for the screen readers.
120+
[styles.aria]: isCategoryList ? !hasStories : !hasCategories,
121+
})}
122+
title={formatMessage(translations.homepage.latestStories)}
119123
/>
124+
{hasCategories && (
125+
<CategoriesFilters
126+
activeCategory={category}
127+
categories={categories}
128+
className={styles.filters}
129+
locale={locale}
130+
/>
131+
)}
120132
{restStories.length > 0 && layout === 'grid' && (
121133
<div
122134
className={classNames(styles.storiesContainer, {

src/modules/InfiniteStories/ui/CategoriesFilters/CategoriesFilters.module.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
.title {
2-
margin-bottom: $spacing-5;
3-
4-
&.aria {
5-
@include sr-only;
6-
}
7-
}
8-
91
.filters {
102
display: flex;
113
align-items: center;

src/modules/InfiniteStories/ui/CategoriesFilters/CategoriesFilters.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
import type { Category } from '@prezly/sdk/dist/types';
2-
import { FormattedMessage, type Locale, translations, useIntl } from '@prezly/theme-kit-nextjs';
2+
import { FormattedMessage, type Locale, translations } from '@prezly/theme-kit-nextjs';
33
import classNames from 'classnames';
44
import Link from 'next/link';
55
import type { ReactNode } from 'react';
66

7-
import { PageTitle } from '@/components/PageTitle';
8-
97
import styles from './CategoriesFilters.module.scss';
108

119
interface Props {
1210
activeCategory: Pick<Category, 'id'> | undefined;
1311
categories: Category[];
1412
className?: string;
15-
hasStories: boolean;
1613
locale: Locale.Code;
1714
}
1815

19-
export function CategoriesFilters({
20-
activeCategory,
21-
categories,
22-
className,
23-
hasStories,
24-
locale,
25-
}: Props) {
26-
const { formatMessage } = useIntl();
27-
16+
export function CategoriesFilters({ activeCategory, categories, className, locale }: Props) {
2817
return (
2918
<div className={className}>
30-
<PageTitle
31-
className={classNames(styles.title, {
32-
// Hide the title for regular visitors if there's no stories,
33-
// but keep it for screen readers
34-
[styles.aria]: !hasStories,
35-
})}
36-
title={formatMessage(translations.homepage.latestStories)}
37-
/>
3819
{categories.length > 0 && (
3920
<div className={styles.filters}>
4021
<Filter isActive={activeCategory === undefined}>

src/modules/Story/RelatedStories/RelatedStories.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { Elements } from '@prezly/content-renderer-react-js';
22
import type { Story } from '@prezly/sdk';
3+
import { type Locale, translations } from '@prezly/theme-kit-nextjs';
34

5+
import { FormattedMessage } from '@/adapters/server';
46
import { Divider } from '@/components/Divider';
57

68
interface Props {
9+
locale: Locale.Code;
710
stories: Story[];
811
}
912

10-
export function RelatedStories({ stories }: Props) {
13+
export function RelatedStories({ locale, stories }: Props) {
1114
return (
1215
<>
1316
<Divider />
14-
<h2>Latest News</h2>
17+
<h2>
18+
<FormattedMessage for={translations.homepage.latestStories} locale={locale} />
19+
</h2>
1520

1621
<div>
1722
{stories.map((story) => (

0 commit comments

Comments
 (0)