From 7acbe3974391500db0b7620c596dd0da7a511f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Moiti=C3=A9?= Date: Wed, 6 Mar 2024 22:25:17 +0000 Subject: [PATCH] update modals with new categories --- src/components/GlobalModals.js | 17 ++- src/components/modal/ContentModal.js | 116 ++++++++++++++++-- src/components/modal/FavouriteSeriesModal.js | 29 ++++- .../__snapshots__/ContentModal.test.js.snap | 52 +++++++- .../FavouriteSeriesModal.test.js.snap | 2 +- src/i18n.js | 7 -- translations/en.js | 6 + 7 files changed, 199 insertions(+), 30 deletions(-) diff --git a/src/components/GlobalModals.js b/src/components/GlobalModals.js index ad420a4..9a5d24a 100644 --- a/src/components/GlobalModals.js +++ b/src/components/GlobalModals.js @@ -64,7 +64,13 @@ export default function GlobalModals() { content={sortedTracks} idField="pkgid" defaultContent={[...defaultSettings.ownedTracks]} - typeFilter={{ key: 'primaryType', oval: 'oval', road: 'road' }} + typeFilter={{ + key: 'primaryType', + oval: 'oval', + road: 'road', + dirtRoad: 'dirt_road', + dirtOval: 'dirt_oval', + }} save={getSettingUpdater('ownedTracks')} favourites={favouriteTracks} saveFavourites={getSettingUpdater('favouriteTracks')} @@ -78,7 +84,14 @@ export default function GlobalModals() { content={sortedCars} idField="sku" defaultContent={[...defaultSettings.ownedCars]} - typeFilter={{ key: 'discountGroupNames', oval: ['oval car'], road: ['road car'] }} + typeFilter={{ + key: 'categories', + oval: ['oval'], + sportsCar: ['sports_car'], + formulaCar: ['formula_car'], + dirtRoad: ['dirt_road'], + dirtOval: ['dirt_oval'], + }} save={getSettingUpdater('ownedCars')} favourites={favouriteCars} saveFavourites={getSettingUpdater('favouriteCars')} diff --git a/src/components/modal/ContentModal.js b/src/components/modal/ContentModal.js index 7764181..d7870e3 100644 --- a/src/components/modal/ContentModal.js +++ b/src/components/modal/ContentModal.js @@ -27,12 +27,21 @@ type Props = { key: string, oval: string, road: string, + dirtOval: string, + dirtRoad: string, + }|{ + key: string, + oval: string, + formulaCar: string, + sportsCar: string, + dirtOval: string, + dirtRoad: string, } }; export default function ContentModal({ id, isOpen, onClose, title, save, content, idField, defaultContent, ownedContent, favourites, - saveFavourites, typeFilter, + saveFavourites, typeFilter, }: Props) { const { t } = useTranslation(); @@ -95,7 +104,7 @@ export default function ContentModal({

{t('Use the checkbox to set the content you own, and use the star to set your favourite content.')}

-
+
-
+
-
+ + {typeFilter.road ? ( +
+
+ setAllTypeContent('road', newValue)} + > + {t('Select all road')} + +
+ +
+ setAllTypeFavourites('road', newValue)} + /> +
+
+ ) : ( + <> +
+
+ setAllTypeContent('sportsCar', newValue)} + > + {t('Select all sports cars')} + +
+ +
+ setAllTypeFavourites('sportsCar', newValue)} + /> +
+
+
+
+ setAllTypeContent('formulaCar', newValue)} + > + {t('Select all formula cars')} + +
+ +
+ setAllTypeFavourites('formulaCar', newValue)} + /> +
+
+ + )} + + +
+
+ setAllTypeContent('dirtRoad', newValue)} + > + {t('Select all dirt road')} + +
+ +
+ setAllTypeFavourites('dirtRoad', newValue)} + /> +
+
+ +
setAllTypeContent('road', newValue)} + id={`${id}-select-dirt-oval`} + checked={allTypeContentChecked('dirtOval')} + onChange={(newValue) => setAllTypeContent('dirtOval', newValue)} > - {t('Select all road')} + {t('Select all dirt oval')}
setAllTypeFavourites('road', newValue)} + id={`${id}-favourite-dirt-oval`} + enabled={allTypeFavouritesChecked('dirtOval')} + onClick={(newValue) => setAllTypeFavourites('dirtOval', newValue)} />
diff --git a/src/components/modal/FavouriteSeriesModal.js b/src/components/modal/FavouriteSeriesModal.js index cf4256e..0efab14 100644 --- a/src/components/modal/FavouriteSeriesModal.js +++ b/src/components/modal/FavouriteSeriesModal.js @@ -36,14 +36,23 @@ const groupedSeries = (filteredSeries) => filteredSeries.reduce((grouped, single ], }; } + if (single.catid === 5) { + return { + ...grouped, + sportsCar: [ + ...grouped.sportsCar, + single, + ], + }; + } return { ...grouped, - road: [ - ...grouped.road, + formulaCar: [ + ...grouped.formulaCar, single, ], }; -}, { oval: [], road: [], dirtOval: [], rx: [] }); +}, { oval: [], road: [], dirtOval: [], rx: [], sportsCar: [], formulaCar: [] }); type Props = { onClose: () => void, @@ -126,11 +135,19 @@ export default function FavouriteSeriesModal({ onClose, isOpen, favouriteSeries,
)} - {groupedSeries(getFilteredSeries()).road.length > 0 && ( + {groupedSeries(getFilteredSeries()).sportsCar.length > 0 && ( + <> +

{t('Sports Car')}

+
+ {groupedSeries(getFilteredSeries()).sportsCar.map(renderCheckboxes)} +
+ + )} + {groupedSeries(getFilteredSeries()).formulaCar.length > 0 && ( <> -

{t('Road')}

+

{t('Formula Car')}

- {groupedSeries(getFilteredSeries()).road.map(renderCheckboxes)} + {groupedSeries(getFilteredSeries()).formulaCar.map(renderCheckboxes)}
)} diff --git a/src/components/modal/__tests__/__snapshots__/ContentModal.test.js.snap b/src/components/modal/__tests__/__snapshots__/ContentModal.test.js.snap index ca4dd20..51ade0a 100644 --- a/src/components/modal/__tests__/__snapshots__/ContentModal.test.js.snap +++ b/src/components/modal/__tests__/__snapshots__/ContentModal.test.js.snap @@ -19,7 +19,7 @@ exports[`components/modal/ContentModal renders correctly 1`] = ` className="row" >
+
+
+ + Select all dirt road + +
+
+ +
+
+
+
+ + Select all dirt oval + +
+
+ +
+

- Road + Sports Car