From 6ac07e9a198074f6b454ed37376d449921b6c17b Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Thu, 14 Dec 2023 15:11:52 +0100 Subject: [PATCH 01/10] Decompose and spread home config un home component --- frontend/src/components/pages/home/Home.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/pages/home/Home.tsx b/frontend/src/components/pages/home/Home.tsx index fda46d173..84bf512f3 100644 --- a/frontend/src/components/pages/home/Home.tsx +++ b/frontend/src/components/pages/home/Home.tsx @@ -14,10 +14,13 @@ const { } = getNextConfig(); const HomeUI: React.FC = () => { - const { config, suggestions } = useHome(); + const { + config: { activityBar, welcomeBanner }, + suggestions, + } = useHome(); const contentContainerClassname = `relative ${ - config.activityBar.shouldDisplay ? '-top-6 desktop:-top-15' : 'pt-6 desktop:pt-18' + activityBar.shouldDisplay ? '-top-6 desktop:-top-15' : 'pt-6 desktop:pt-18' }`; const intl = useIntl(); @@ -32,14 +35,9 @@ const HomeUI: React.FC = () => { description={intl.formatMessage({ id: 'home.description' })} /> - +
- {config.activityBar.shouldDisplay && ( + {activityBar.shouldDisplay && (
Date: Thu, 14 Dec 2023 15:20:55 +0100 Subject: [PATCH 02/10] Add numberOfItemsBeforeTruncation activityBar home config --- frontend/config/home.json | 3 ++- frontend/customization/config/home.json | 3 ++- .../ActivitySearchFilter/ActivitySearchFilter.tsx | 12 +++++++----- frontend/src/components/pages/home/Home.tsx | 4 +++- frontend/src/modules/home/interface.ts | 1 + 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/frontend/config/home.json b/frontend/config/home.json index 79288d93f..c84858fbe 100644 --- a/frontend/config/home.json +++ b/frontend/config/home.json @@ -8,7 +8,8 @@ "shouldDisplayText": true }, "activityBar": { - "shouldDisplay": true + "shouldDisplay": true, + "numberOfItemsBeforeTruncation": 8 }, "suggestions": { "default": [] diff --git a/frontend/customization/config/home.json b/frontend/customization/config/home.json index 60b471703..cf7a0b279 100644 --- a/frontend/customization/config/home.json +++ b/frontend/customization/config/home.json @@ -8,7 +8,8 @@ "shouldDisplayText": true }, "activityBar": { - "shouldDisplay": true + "shouldDisplay": true, + "numberOfItemsBeforeTruncation": 8 }, "suggestions": { "default": [ diff --git a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx index 21d7bf91d..3b1d95396 100644 --- a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx +++ b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx @@ -12,20 +12,22 @@ import { ActivitySearchFilterMobile } from './ActivitySearchFilterMobile'; interface Props { className?: string; + itemsToDisplayBeforeTruncation: number; } -const MAX_VISIBLE_ACTIVITIES = 8; - -export const ActivitySearchFilter: React.FC = ({ className }) => { +export const ActivitySearchFilter: React.FC = ({ + className, + itemsToDisplayBeforeTruncation = 8, +}) => { const { activities, expandedState, toggleExpandedState } = useActivitySearchFilter(); const collapseIsNeeded: boolean = - activities !== undefined && activities.length > MAX_VISIBLE_ACTIVITIES; + activities !== undefined && activities.length > itemsToDisplayBeforeTruncation; const visibleActivities: ActivityFilter[] | undefined = activities !== undefined ? collapseIsNeeded && expandedState === 'COLLAPSED' - ? activities.slice(0, MAX_VISIBLE_ACTIVITIES) + ? activities.slice(0, itemsToDisplayBeforeTruncation) : activities : undefined; diff --git a/frontend/src/components/pages/home/Home.tsx b/frontend/src/components/pages/home/Home.tsx index 84bf512f3..35c593b36 100644 --- a/frontend/src/components/pages/home/Home.tsx +++ b/frontend/src/components/pages/home/Home.tsx @@ -42,7 +42,9 @@ const HomeUI: React.FC = () => { className={`desktop:flex desktop:justify-center ${classNameHomeChild}`} id="home_activitiesBar" > - +
)} {homeTop !== undefined && ( diff --git a/frontend/src/modules/home/interface.ts b/frontend/src/modules/home/interface.ts index 72e25a53b..3f8e880c5 100644 --- a/frontend/src/modules/home/interface.ts +++ b/frontend/src/modules/home/interface.ts @@ -1,5 +1,6 @@ interface ActivityBar { shouldDisplay: boolean; + numberOfItemsBeforeTruncation: number; } interface WelcomeBanner { From 72e15f974736b356a6f18465425204a55c3394ff Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Thu, 14 Dec 2023 15:33:50 +0100 Subject: [PATCH 03/10] Rewrite ActivitySearchFilter component --- .../ActivitySearchFilter.tsx | 86 +++++++++---------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx index 3b1d95396..0c241b7a5 100644 --- a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx +++ b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx @@ -1,11 +1,11 @@ import { ChevronDown } from 'components/Icons/ChevronDown'; import { MoreHorizontal } from 'components/Icons/MoreHorizontal'; -import React from 'react'; import { FormattedMessage } from 'react-intl'; import { routes } from 'services/routes'; import { ActivityFilter } from 'modules/activities/interface'; import { CATEGORY_ID, EVENT_ID, OUTDOOR_ID, PRACTICE_ID } from 'modules/filters/constant'; +import { cn } from 'services/utils/cn'; import { ActivityButton } from './ActivityButton'; import { useActivitySearchFilter } from './useActivitySearchFilter'; import { ActivitySearchFilterMobile } from './ActivitySearchFilterMobile'; @@ -21,16 +21,6 @@ export const ActivitySearchFilter: React.FC = ({ }) => { const { activities, expandedState, toggleExpandedState } = useActivitySearchFilter(); - const collapseIsNeeded: boolean = - activities !== undefined && activities.length > itemsToDisplayBeforeTruncation; - - const visibleActivities: ActivityFilter[] | undefined = - activities !== undefined - ? collapseIsNeeded && expandedState === 'COLLAPSED' - ? activities.slice(0, itemsToDisplayBeforeTruncation) - : activities - : undefined; - const getId = (type: string) => { if (type === 'PRACTICE') return PRACTICE_ID; if (type === 'OUTDOOR_PRACTICE') return OUTDOOR_ID; @@ -39,41 +29,49 @@ export const ActivitySearchFilter: React.FC = ({ return CATEGORY_ID; }; + if (activities === undefined) { + return null; + } + + const collapseIsNeeded: boolean = activities.length > itemsToDisplayBeforeTruncation; + + const visibleActivities: ActivityFilter[] = + collapseIsNeeded && expandedState === 'COLLAPSED' + ? activities.slice(0, itemsToDisplayBeforeTruncation) + : activities; + return ( -
- {activities !== undefined && ( - <> - + + + )} +
+
+ +
+ ); }; From f5f388a7b295ef7be7779e6700284d6fa2e5c74e Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Fri, 15 Dec 2023 14:59:31 +0100 Subject: [PATCH 04/10] Create practice-trek icon --- frontend/src/public/icons/practice-trek.svg | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 frontend/src/public/icons/practice-trek.svg diff --git a/frontend/src/public/icons/practice-trek.svg b/frontend/src/public/icons/practice-trek.svg new file mode 100644 index 000000000..4984eb81d --- /dev/null +++ b/frontend/src/public/icons/practice-trek.svg @@ -0,0 +1,12 @@ + + + \ No newline at end of file From 86fbc48331aded7d5c49a1bac61bd4693bfc6739 Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Fri, 15 Dec 2023 15:02:41 +0100 Subject: [PATCH 05/10] Handle barActivity translations --- .../ActivitySearchFilter/ActivitySearchFilter.tsx | 11 ++++++++--- frontend/src/modules/activities/interface.ts | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx index 0c241b7a5..db8a75e41 100644 --- a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx +++ b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilter.tsx @@ -1,6 +1,6 @@ import { ChevronDown } from 'components/Icons/ChevronDown'; import { MoreHorizontal } from 'components/Icons/MoreHorizontal'; -import { FormattedMessage } from 'react-intl'; +import { FormattedMessage, useIntl } from 'react-intl'; import { routes } from 'services/routes'; import { ActivityFilter } from 'modules/activities/interface'; import { CATEGORY_ID, EVENT_ID, OUTDOOR_ID, PRACTICE_ID } from 'modules/filters/constant'; @@ -20,6 +20,7 @@ export const ActivitySearchFilter: React.FC = ({ itemsToDisplayBeforeTruncation = 8, }) => { const { activities, expandedState, toggleExpandedState } = useActivitySearchFilter(); + const intl = useIntl(); const getId = (type: string) => { if (type === 'PRACTICE') return PRACTICE_ID; @@ -29,7 +30,7 @@ export const ActivitySearchFilter: React.FC = ({ return CATEGORY_ID; }; - if (activities === undefined) { + if (!activities) { return null; } @@ -54,7 +55,11 @@ export const ActivitySearchFilter: React.FC = ({ iconUrl={activity.pictogramUri} href={`${routes.SEARCH}?${getId(activity.type)}=${activity.id}`} key={`${activity.type}-${activity.id}`} - label={activity.label} + label={ + activity.titleTranslationId + ? intl.formatMessage({ id: activity.titleTranslationId }) + : activity.label + } /> ))}
diff --git a/frontend/src/modules/activities/interface.ts b/frontend/src/modules/activities/interface.ts index c7c59f821..e22e07d74 100644 --- a/frontend/src/modules/activities/interface.ts +++ b/frontend/src/modules/activities/interface.ts @@ -26,4 +26,5 @@ export interface ActivityFilter extends Activity { id: number | string; order: null | number; type: 'PRACTICE' | 'OUTDOOR_PRACTICE' | 'CATEGORY' | 'TOURISTIC_EVENT_TYPE'; + titleTranslationId?: string; } From 6c414c8aa69fa6ca9ac209624a41e109ec8525b3 Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Fri, 15 Dec 2023 15:03:54 +0100 Subject: [PATCH 06/10] Add activityBar links to the config --- frontend/config/home.json | 18 +++++++++++++++++- frontend/customization/config/home.json | 18 +++++++++++++++++- frontend/src/modules/home/interface.ts | 8 +++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/frontend/config/home.json b/frontend/config/home.json index c84858fbe..205d1e91d 100644 --- a/frontend/config/home.json +++ b/frontend/config/home.json @@ -9,7 +9,23 @@ }, "activityBar": { "shouldDisplay": true, - "numberOfItemsBeforeTruncation": 8 + "numberOfItemsBeforeTruncation": 8, + "links": [{ + "type": "trek", + "grouped": false + }, + { + "type": "outdoorSite", + "grouped": false + }, + { + "type": "touristicContent", + "grouped": false + }, + { + "type": "touristicEvent", + "grouped": false + }] }, "suggestions": { "default": [] diff --git a/frontend/customization/config/home.json b/frontend/customization/config/home.json index cf7a0b279..1cb315c49 100644 --- a/frontend/customization/config/home.json +++ b/frontend/customization/config/home.json @@ -9,7 +9,23 @@ }, "activityBar": { "shouldDisplay": true, - "numberOfItemsBeforeTruncation": 8 + "numberOfItemsBeforeTruncation": 8, + "links": [{ + "type": "trek", + "grouped": false + }, + { + "type": "outdoorSite", + "grouped": false + }, + { + "type": "touristicContent", + "grouped": false + }, + { + "type": "touristicEvent", + "grouped": false + }] }, "suggestions": { "default": [ diff --git a/frontend/src/modules/home/interface.ts b/frontend/src/modules/home/interface.ts index 3f8e880c5..419bb4c42 100644 --- a/frontend/src/modules/home/interface.ts +++ b/frontend/src/modules/home/interface.ts @@ -1,6 +1,12 @@ -interface ActivityBar { +export interface ActivityBar { shouldDisplay: boolean; numberOfItemsBeforeTruncation: number; + links: ActivityBarLinks[]; +} + +export interface ActivityBarLinks { + type: 'trek' | 'outdoorSite' | 'touristicContent' | 'touristicEvent'; + grouped: boolean; } interface WelcomeBanner { From f5638aefad9949f1258f075d26b2ce09afad74d2 Mon Sep 17 00:00:00 2001 From: Florian Sommariva Date: Fri, 15 Dec 2023 15:14:23 +0100 Subject: [PATCH 07/10] Handle barActivity with config --- .../ActivitySearchFilterMobile/index.tsx | 7 +-- .../useActivitySearchFilter.ts | 5 +- frontend/src/modules/activities/adapter.ts | 23 ++++++++- frontend/src/modules/activities/connector.ts | 51 ++++++++++++------- .../src/modules/outdoorPractice/adapter.ts | 22 +++++++- .../touristicContentCategory/adapter.ts | 23 ++++++++- .../src/modules/touristicEventType/adapter.ts | 22 +++++++- frontend/src/pages/index.tsx | 2 +- frontend/src/translations/ca.json | 10 +++- frontend/src/translations/de.json | 8 ++- frontend/src/translations/en.json | 8 ++- frontend/src/translations/es.json | 10 +++- frontend/src/translations/fr.json | 8 ++- frontend/src/translations/it.json | 8 ++- 14 files changed, 168 insertions(+), 39 deletions(-) diff --git a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilterMobile/index.tsx b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilterMobile/index.tsx index 3c6ddd55b..a38a2c656 100644 --- a/frontend/src/components/ActivitySearchFilter/ActivitySearchFilterMobile/index.tsx +++ b/frontend/src/components/ActivitySearchFilter/ActivitySearchFilterMobile/index.tsx @@ -1,6 +1,6 @@ import React from 'react'; import Select, { CSSObjectWithLabel } from 'react-select'; -import { FormattedMessage } from 'react-intl'; +import { FormattedMessage, useIntl } from 'react-intl'; import { colorPalette, getSpacing, shadow } from 'stylesheet'; import { routes } from 'services/routes'; @@ -17,6 +17,7 @@ export const ActivitySearchFilterMobile: React.FC<{ getId: (type: string) => string; }> = ({ className = '', activities, getId }) => { const { selectedActivityId, updateSelectedActivityId } = useActivitySearchFilterMobile(); + const intl = useIntl(); const selectedActivity = activities.find( ({ id, type }) => `${type}-${id}` === selectedActivityId, @@ -26,9 +27,9 @@ export const ActivitySearchFilterMobile: React.FC<{