From d508a69f62143c40192c266206b76e0c9966edae Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Thu, 15 Jun 2023 11:21:04 +0200 Subject: [PATCH 1/2] Rewrite DetailsChildrenSection component to be more generic --- .../src/components/pages/details/Details.tsx | 6 +- .../DetailsChildrenSection.tsx | 155 +++++++++++------- .../src/components/pages/details/utils.tsx | 4 +- 3 files changed, 99 insertions(+), 66 deletions(-) diff --git a/frontend/src/components/pages/details/Details.tsx b/frontend/src/components/pages/details/Details.tsx index 7ede598c6..f3e9e70e4 100644 --- a/frontend/src/components/pages/details/Details.tsx +++ b/frontend/src/components/pages/details/Details.tsx @@ -189,15 +189,17 @@ export const DetailsUIWithoutContext: React.FC = ({ detailsId, parentId, {details.children.length > 0 && (
({ + id="children" + items={details.children.map(child => ({ ...child, id: `${child.id}`, }))} - trekId={id} + parentId={id} title={intl.formatMessage( { id: 'details.childrenFullTitle' }, { count: details.children.length }, )} + type="TREK" />
)} diff --git a/frontend/src/components/pages/details/components/DetailsChildrenSection/DetailsChildrenSection.tsx b/frontend/src/components/pages/details/components/DetailsChildrenSection/DetailsChildrenSection.tsx index e1c728c0b..c77ba40ae 100644 --- a/frontend/src/components/pages/details/components/DetailsChildrenSection/DetailsChildrenSection.tsx +++ b/frontend/src/components/pages/details/components/DetailsChildrenSection/DetailsChildrenSection.tsx @@ -1,71 +1,113 @@ import { Separator } from 'components/Separator'; import { TrekResult } from 'modules/results/interface'; +import { OutdoorSiteResult } from 'modules/outdoorSite/interface'; +import { OutdoorCourseResult } from 'modules/outdoorCourse/interface'; import { ResultCard } from 'components/pages/search/components/ResultCard'; import styled, { css } from 'styled-components'; import { desktopOnly, scrollBar, sizes } from 'stylesheet'; +import { cn } from 'services/utils/cn'; import { marginDetailsChild } from '../../Details'; -import { generateChildrenDetailsUrl } from '../../utils'; +import { generateDetailsUrlFromType } from '../../utils'; interface DetailsChildrenSectionProps { - trekChildren: TrekResult[]; + id?: string; + items: TrekResult[] | OutdoorSiteResult[] | OutdoorCourseResult[]; + parentId?: string; title: string; - trekId: string; + type: 'TREK' | 'OUTDOOR_SITE' | 'OUTDOOR_COURSE'; } export const DetailsChildrenSection: React.FC = ({ - trekChildren, + items, title, - trekId, + parentId, + type, + id = `${type.toLocaleLowerCase()}Children`, }) => { + const withSteps = parentId !== undefined; + const idAttribute = `details_${id}`; return ( -
-
+

{title} -

+ - {trekChildren.map((trekChild, i) => ( -
-
- -
-
-
- -
-
-
+ {items.map(item => ( +
  • + +
  • ))}
    @@ -77,7 +119,7 @@ export const DetailsChildrenSection: React.FC = ({ const offsetTopForTitle = 130; -const ScrollContainer = styled.div` +const ScrollContainer = styled.ul` &::-webkit-scrollbar { ${scrollBar.root} } @@ -90,16 +132,3 @@ const ScrollContainer = styled.div` ); `)} `; - -const Step: React.FC<{ number: number }> = ({ number }) => ( -
    - {number} -
    -); diff --git a/frontend/src/components/pages/details/utils.tsx b/frontend/src/components/pages/details/utils.tsx index c4c9cf211..ccc0b120d 100644 --- a/frontend/src/components/pages/details/utils.tsx +++ b/frontend/src/components/pages/details/utils.tsx @@ -147,7 +147,9 @@ export const generateDetailsUrlFromType = ( type: 'TREK' | 'TOURISTIC_CONTENT' | 'TOURISTIC_EVENT' | 'OUTDOOR_SITE' | 'OUTDOOR_COURSE', id: number | string, title: string, + params?: Record, ): string => { + const searchParams = params ? `?${new URLSearchParams(params).toString()}` : ''; const titleWithNoSpace = convertStringForSitemap(title); - return `${routes[type]}/${id}-${encodeURI(titleWithNoSpace)}`; + return `${routes[type]}/${id}-${encodeURI(titleWithNoSpace)}${searchParams}`; }; From f89154dd0d55e8186f5bed5422eb723537060847 Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Thu, 15 Jun 2023 11:23:57 +0200 Subject: [PATCH 2/2] Use DetailsChildrenSection for all outdoor site children cards --- .../components/pages/site/OutdoorSiteUI.tsx | 39 +++++----- .../AccessChildrenSection/index.tsx | 78 ------------------- .../OutdoorCoursesChildrenSection/index.tsx | 74 ------------------ .../OutdoorSiteChildrenSection/index.tsx | 78 ------------------- 4 files changed, 20 insertions(+), 249 deletions(-) delete mode 100644 frontend/src/components/pages/site/components/AccessChildrenSection/index.tsx delete mode 100644 frontend/src/components/pages/site/components/OutdoorCoursesChildrenSection/index.tsx delete mode 100644 frontend/src/components/pages/site/components/OutdoorSiteChildrenSection/index.tsx diff --git a/frontend/src/components/pages/site/OutdoorSiteUI.tsx b/frontend/src/components/pages/site/OutdoorSiteUI.tsx index 780ef3d2c..ba7fc1fb2 100644 --- a/frontend/src/components/pages/site/OutdoorSiteUI.tsx +++ b/frontend/src/components/pages/site/OutdoorSiteUI.tsx @@ -13,10 +13,8 @@ import { DetailsHeaderMobile, marginDetailsChild } from 'components/pages/detail import { useOnScreenSection } from 'components/pages/details/hooks/useHighlightedSection'; import { generateTouristicContentUrl, HtmlText } from 'components/pages/details/utils'; import { VisibleSectionProvider } from 'components/pages/details/VisibleSectionContext'; -import { AccessChildrenSection } from 'components/pages/site/components/AccessChildrenSection'; -import { OutdoorCoursesChildrenSection } from 'components/pages/site/components/OutdoorCoursesChildrenSection'; -import { OutdoorSiteChildrenSection } from 'components/pages/site/components/OutdoorSiteChildrenSection'; -import React, { useMemo, useRef } from 'react'; +import { DetailsChildrenSection } from 'components/pages/details/components/DetailsChildrenSection'; +import { useMemo, useRef } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import Loader from 'components/Loader'; import { useMediaPredicate } from 'react-media-hook'; @@ -218,28 +216,30 @@ const OutdoorSiteUIWithoutContext: React.FC = ({ outdoorSiteUrl, language
    )} - {Number(outdoorSiteContent?.children?.length) > 0 && ( + {Number(outdoorSiteContent.children?.length) > 0 && (
    -
    )} - {Number(outdoorSiteContent?.courses?.length) > 0 && ( + {Number(outdoorSiteContent.courses?.length) > 0 && (
    -
    )} @@ -304,15 +304,16 @@ const OutdoorSiteUIWithoutContext: React.FC = ({ outdoorSiteUrl, language )} - {Number(outdoorSiteContent?.access?.length) > 0 && ( + {Number(outdoorSiteContent.access?.length) > 0 && (
    -
    )} diff --git a/frontend/src/components/pages/site/components/AccessChildrenSection/index.tsx b/frontend/src/components/pages/site/components/AccessChildrenSection/index.tsx deleted file mode 100644 index f1097852d..000000000 --- a/frontend/src/components/pages/site/components/AccessChildrenSection/index.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { marginDetailsChild } from 'components/pages/details/Details'; -import { generateResultDetailsUrl } from 'components/pages/search/utils'; -import { Separator } from 'components/Separator'; -import { ResultCard } from 'components/pages/search/components/ResultCard'; -import React from 'react'; -import styled, { css } from 'styled-components'; -import { desktopOnly, scrollBar, sizes } from 'stylesheet'; -import { TrekResult } from '../../../../../modules/results/interface'; - -interface DetailsChildrenSectionProps { - accessChildren: TrekResult[]; - title: string; - id: string; -} - -export const AccessChildrenSection: React.FC = ({ - accessChildren, - title, -}) => { - return ( -
    -
    - {title} -
    - - {accessChildren.map(trekChild => ( -
    - -
    - ))} -
    -
    - -
    -
    - ); -}; - -const offsetTopForTitle = 130; - -const ScrollContainer = styled.div` - &::-webkit-scrollbar { - ${scrollBar.root} - } - &::-webkit-scrollbar-thumb { - ${scrollBar.thumb} - } - ${desktopOnly(css` - max-height: calc( - 100vh - ${sizes.desktopHeader + sizes.detailsHeaderDesktop + offsetTopForTitle}px - ); - `)} -`; diff --git a/frontend/src/components/pages/site/components/OutdoorCoursesChildrenSection/index.tsx b/frontend/src/components/pages/site/components/OutdoorCoursesChildrenSection/index.tsx deleted file mode 100644 index 5754b8a40..000000000 --- a/frontend/src/components/pages/site/components/OutdoorCoursesChildrenSection/index.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import { marginDetailsChild } from 'components/pages/details/Details'; -import { generateOutdoorCourseUrl } from 'components/pages/details/utils'; -import { Separator } from 'components/Separator'; -import { ResultCard } from 'components/pages/search/components/ResultCard'; -import React from 'react'; -import styled, { css } from 'styled-components'; -import { desktopOnly, scrollBar, sizes } from 'stylesheet'; -import { OutdoorCourseResult } from '../../../../../modules/outdoorCourse/interface'; - -interface DetailsChildrenSectionProps { - outdoorChildren: OutdoorCourseResult[]; - title: string; - id: string; -} - -export const OutdoorCoursesChildrenSection: React.FC = ({ - outdoorChildren, - title, -}) => { - return ( -
    -
    - {title} -
    - - {outdoorChildren.map(trekChild => ( -
    - -
    - ))} -
    -
    - -
    -
    - ); -}; - -const offsetTopForTitle = 130; - -const ScrollContainer = styled.div` - &::-webkit-scrollbar { - ${scrollBar.root} - } - &::-webkit-scrollbar-thumb { - ${scrollBar.thumb} - } - ${desktopOnly(css` - max-height: calc( - 100vh - ${sizes.desktopHeader + sizes.detailsHeaderDesktop + offsetTopForTitle}px - ); - `)} -`; diff --git a/frontend/src/components/pages/site/components/OutdoorSiteChildrenSection/index.tsx b/frontend/src/components/pages/site/components/OutdoorSiteChildrenSection/index.tsx deleted file mode 100644 index e8b734fd5..000000000 --- a/frontend/src/components/pages/site/components/OutdoorSiteChildrenSection/index.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { marginDetailsChild } from 'components/pages/details/Details'; -import { generateOutdoorSiteUrl } from 'components/pages/details/utils'; -import { Separator } from 'components/Separator'; -import { ResultCard } from 'components/pages/search/components/ResultCard'; -import React from 'react'; -import styled, { css } from 'styled-components'; -import { desktopOnly, scrollBar, sizes } from 'stylesheet'; -import { OutdoorSiteResult } from '../../../../../modules/outdoorSite/interface'; - -interface DetailsChildrenSectionProps { - outdoorChildren: OutdoorSiteResult[]; - title: string; - id: string; -} - -export const OutdoorSiteChildrenSection: React.FC = ({ - outdoorChildren, - title, -}) => { - return ( -
    -
    - {title} -
    - - {outdoorChildren.map(trekChild => ( -
    - -
    - ))} -
    -
    - -
    -
    - ); -}; - -const offsetTopForTitle = 130; - -const ScrollContainer = styled.div` - &::-webkit-scrollbar { - ${scrollBar.root} - } - &::-webkit-scrollbar-thumb { - ${scrollBar.thumb} - } - ${desktopOnly(css` - max-height: calc( - 100vh - ${sizes.desktopHeader + sizes.detailsHeaderDesktop + offsetTopForTitle}px - ); - `)} -`;