Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle flatpage #1078

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,13 @@ Object {
id="accordion__panel-:r1:"
>
<a
class="hover:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
class="hover:text-primary3 focus:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
href="/"
>
FR
</a>
<a
class="hover:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
class="hover:text-primary3 focus:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
href="/"
>
EN
Expand Down Expand Up @@ -1290,13 +1290,13 @@ Object {
id="accordion__panel-:r1:"
>
<a
class="hover:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
class="hover:text-primary3 focus:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
href="/"
>
FR
</a>
<a
class="hover:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
class="hover:text-primary3 focus:text-primary3 transition-colors block text-Mobile-C2 py-2 text-greyDarkColored"
href="/"
>
EN
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export const Link: React.FC<Props> = ({ children, className = '', testId, ...nex
return (
<NextLink passHref legacyBehavior {...nextLinkProps}>
<a
className={cn('text-primary1 hover:text-primary3 transition-colors', className)}
className={cn(
'text-primary1 hover:text-primary3 focus:text-primary3 transition-colors',
className,
)}
data-testid={testId}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/596-Boucle-de-malade?parentId=501"
>
<div
Expand Down Expand Up @@ -65,7 +65,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/604-Deuxieme-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -97,7 +97,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/2-Troisieme-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -129,7 +129,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/4-Quatrieme-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -161,7 +161,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/5-Encore-une-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -193,7 +193,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/6-C-est-la-fin-!?parentId=501"
>
<div
Expand Down Expand Up @@ -248,7 +248,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/596-Boucle-de-malade?parentId=501"
>
<div
Expand Down Expand Up @@ -280,7 +280,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/604-Deuxieme-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -312,7 +312,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/2-Troisieme-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -344,7 +344,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/4-Quatrieme-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -376,7 +376,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/5-Encore-une-etape?parentId=501"
>
<div
Expand Down Expand Up @@ -408,7 +408,7 @@ Object {
tabindex="-1"
>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/6-C-est-la-fin-!?parentId=501"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object {
"baseElement": <body>
<div>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/1-Test-rando-mere"
>
<span
Expand Down Expand Up @@ -46,7 +46,7 @@ Object {
</body>,
"container": <div>
<a
class="text-primary1 hover:text-primary3 transition-colors"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors"
href="/trek/1-Test-rando-mere"
>
<span
Expand Down
72 changes: 55 additions & 17 deletions frontend/src/components/pages/flatPage/FlatPage.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
import { useMemo } from 'react';
import Loader from 'components/Loader';
import Image from 'next/image';
import { colorPalette } from 'stylesheet';
import parse from 'html-react-parser';
import parse, { DOMNode, Element } from 'html-react-parser';
import { Footer } from 'components/Footer';
import { Separator } from 'components/Separator';
import { PageHead } from 'components/PageHead';
import styled from 'styled-components';
import { FormattedMessage, useIntl } from 'react-intl';
import { generateFlatPageUrl } from 'modules/header/utills';
import { getGlobalConfig } from 'modules/utils/api.config';
import { getSuggestionType } from 'modules/flatpage/utils';
import { useFlatPage } from './useFlatPage';
import { DetailsSection } from '../details/components/DetailsSection';
import { ErrorFallback } from '../search/components/ErrorFallback';
import { DetailsSource } from '../details/components/DetailsSource';
import { HtmlText } from '../details/utils';
import Breadcrumb from '../details/components/DetailsPreview/Breadcrumb';
import { HomeSection } from '../home/components/HomeSection';

interface FlatPageUIProps {
flatPageUrl: string;
}

export const FlatPageUI: React.FC<FlatPageUIProps> = ({ flatPageUrl }) => {
const { flatPage, isLoading, refetch } = useFlatPage(flatPageUrl);
const { flatPage, isLoading, refetch, activitySuggestions } = useFlatPage(flatPageUrl);
const intl = useIntl();

const parsedFlatPage = useMemo(() => {
if (!flatPage?.content || !flatPage.content.length) {
return null;
}
return parse(flatPage.content, {
replace: (domNode: DOMNode) => {
if (
domNode instanceof Element &&
domNode.attribs &&
'data-ids' in domNode.attribs &&
'data-type' in domNode.attribs &&
domNode.attribs.class.includes('suggestions')
) {
const suggestion = activitySuggestions.find(
item =>
item.results.map(({ id }) => id).join(',') ===
domNode.attribs['data-ids'] &&
item.type === getSuggestionType(domNode.attribs['data-type']),
);
if (!suggestion || suggestion.results.length === 0) {
return null;
}
return (
<HomeSection
title={suggestion.titleTranslationId}
iconUrl={suggestion.iconUrl}
results={suggestion.results}
asColumn
/>
);
}
return domNode;
},
});
}, [activitySuggestions, flatPage?.content] );

return (
<>
<PageHead
Expand All @@ -38,7 +76,7 @@ export const FlatPageUI: React.FC<FlatPageUIProps> = ({ flatPageUrl }) => {
)
) : (
<div id="flatPage_container">
{flatPage.attachment !== null && flatPage.attachment.length > 0 && (
{flatPage.attachment && flatPage.attachment.length > 0 && (
<div
className="relative coverDetailsMobile desktop:h-coverDetailsDesktop text-center"
id="flatPage_cover"
Expand All @@ -60,27 +98,27 @@ export const FlatPageUI: React.FC<FlatPageUIProps> = ({ flatPageUrl }) => {
</TextWithShadow>
</div>
)}
<div className="px-4 desktop:px-10vw py-4 desktop:py-10" id="flatPage_content">
<div className="px-4 mx-auto max-w-[900px]" id="flatPage_content">
{(flatPage.attachment == null || flatPage.attachment.length === 0) && (
<div className="flex justify-center py-6 desktop:py-12">
<h1 className="text-H3 desktop:text-H1 font-bold text-primary1 text-center">
{flatPage.title}
</h1>
</div>
)}
<div className="ml-5">
<Breadcrumb
breadcrumb={[
{
label: intl.formatMessage({ id: 'header.home' }),
link: '/',
},
{ label: flatPage?.title },
]}
/>
</div>
<Breadcrumb
breadcrumb={[
{
label: intl.formatMessage({ id: 'header.home' }),
link: '/',
},
{ label: flatPage?.title },
]}
/>
{flatPage.content !== null && flatPage.content.length > 0 && (
<HtmlText className="mb-10">{parse(flatPage.content)}</HtmlText>
<div className="custo-page-WYSIWYG mb-10 text-lg desktop:text-xl">
{parsedFlatPage}
</div>
)}
{flatPage.sources.length > 0 && (
<>
Expand Down
32 changes: 30 additions & 2 deletions frontend/src/components/pages/flatPage/useFlatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { useRouter } from 'next/router';
import { useQuery } from '@tanstack/react-query';
import { ONE_DAY } from 'services/constants/staleTime';
import { useQueryCommonDictionaries } from 'modules/dictionaries/api';
import { getSuggestionsFromContent } from 'modules/flatpage/utils';
import { ActivitySuggestion } from 'modules/activitySuggestions/interface';
import { getActivitySuggestions } from 'modules/activitySuggestions/connector';

export const useFlatPage = (flatPageUrl: string | undefined) => {
const language = useRouter().locale ?? getDefaultLanguage();
Expand All @@ -14,13 +17,38 @@ export const useFlatPage = (flatPageUrl: string | undefined) => {

const commonDictionaries = useQueryCommonDictionaries(language);

const { data, refetch, isLoading, error } = useQuery<FlatPageDetails, Error>(
const {
data: flatPage,
refetch,
isLoading,
error,
} = useQuery<FlatPageDetails, Error>(
['flatPageDetails', id, language],
() => getFlatPageDetails(id, language, commonDictionaries),
{
enabled: isUrlString(flatPageUrl) && commonDictionaries !== undefined,
staleTime: ONE_DAY,
},
);
return { id, flatPage: data, refetch, isLoading, error, path };
const suggestions = getSuggestionsFromContent(flatPage?.content ?? '');

const activitySuggestionIds = suggestions.flatMap(suggestion =>
'ids' in suggestion ? suggestion.ids : [suggestion.type],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'ids' in suggestion ? suggestion.ids : [suggestion.type],
suggestion.ids ?? [suggestion.type],

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My code is a bit tricky because I have a little problem with the suggestion type, which thinks ids doesn't exist, but it does. 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thx for the suggestion 🙏

);

const { data: activitySuggestions = [] } = useQuery<ActivitySuggestion[] | [], Error>(
['activitySuggestions', ...activitySuggestionIds, id, language],
() => getActivitySuggestions(suggestions, language, commonDictionaries),
{ enabled: suggestions.length > 0 && commonDictionaries !== undefined },
);

return {
id,
flatPage,
activitySuggestions,
refetch,
isLoading,
error,
path,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ResultCard: React.FC<ResultCardProps> = props => {
setHoveredCardId(null);
}}
className={cn(
'flex flex-auto flex-col items-stretch border border border-solid border-greySoft hover:border-blackSemiTransparent transition rounded-xl overflow-hidden cursor-pointer',
'custo-result-card flex flex-auto flex-col items-stretch border border border-solid border-greySoft hover:border-blackSemiTransparent transition rounded-xl overflow-hidden',
asColumn !== true && 'desktop:flex-row',
className,
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object {
"baseElement": <body>
<div>
<div
class="flex flex-auto flex-col items-stretch border border-solid border-greySoft hover:border-blackSemiTransparent transition rounded-xl overflow-hidden cursor-pointer desktop:flex-row"
class="custo-result-card flex flex-auto flex-col items-stretch border border-solid border-greySoft hover:border-blackSemiTransparent transition rounded-xl overflow-hidden desktop:flex-row"
id="result_card"
>
<div
Expand Down Expand Up @@ -46,7 +46,7 @@ Object {
</div>
</div>
<a
class="text-primary1 hover:text-primary3 transition-colors w-full"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors w-full"
data-testid="Link-ResultCard-2"
href="/details-2-Balade-au-pays-des-menhirs"
>
Expand Down Expand Up @@ -219,7 +219,7 @@ Object {
</body>,
"container": <div>
<div
class="flex flex-auto flex-col items-stretch border border-solid border-greySoft hover:border-blackSemiTransparent transition rounded-xl overflow-hidden cursor-pointer desktop:flex-row"
class="custo-result-card flex flex-auto flex-col items-stretch border border-solid border-greySoft hover:border-blackSemiTransparent transition rounded-xl overflow-hidden desktop:flex-row"
id="result_card"
>
<div
Expand Down Expand Up @@ -259,7 +259,7 @@ Object {
</div>
</div>
<a
class="text-primary1 hover:text-primary3 transition-colors w-full"
class="text-primary1 hover:text-primary3 focus:text-primary3 transition-colors w-full"
data-testid="Link-ResultCard-2"
href="/details-2-Balade-au-pays-des-menhirs"
>
Expand Down
Loading
Loading