Skip to content

Commit

Permalink
Atlas - Impossible réinitialiser la liste des favoris (et d'ailleurs,…
Browse files Browse the repository at this point in the history
… comment se génère-t-elle ?) #61
  • Loading branch information
jerem1508 committed Dec 13, 2024
1 parent 7cf787a commit 2022c01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
29 changes: 14 additions & 15 deletions client/src/pages/atlas/components/home-map-cards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type TerritoiresListProps = {

import { GetLevelBadgeFromId } from "../../utils/badges.tsx";
import { DEFAULT_CURRENT_YEAR } from "../../../../constants.tsx";
import { useState } from "react";

function getRandomElementsFromArray(
territoiresList: TerritoiresListProps[],
Expand All @@ -36,22 +37,20 @@ function getTerritoiresList(
const territoiresInFavorites = territoiresList
.filter((territoire) => favorites.includes(territoire?.id))
.slice(0, nbmax);
const territoiresNotInFavorites = territoiresList.filter(
(territoire) => !favorites.includes(territoire?.id)
);
// const territoiresNotInFavorites = territoiresList.filter(
// (territoire) => !favorites.includes(territoire?.id)
// );

const territoiresNotInFavoritesShuffled = getRandomElementsFromArray(
territoiresNotInFavorites,
nbmax - territoiresInFavorites.length
);
return [...territoiresInFavorites, ...territoiresNotInFavoritesShuffled];
// const territoiresNotInFavoritesShuffled = getRandomElementsFromArray(
// territoiresNotInFavorites,
// nbmax - territoiresInFavorites.length
// );
// return [...territoiresInFavorites, ...territoiresNotInFavoritesShuffled];
return [...territoiresInFavorites];
}

export default function HomeMapCards({
territoiresList = [],
}: {
territoiresList: TerritoiresListProps[];
}) {
export default function HomeMapCards({ territoiresList }: { territoiresList: TerritoiresListProps[] }) {
const [refresh, setRefresh] = useState(0);
// get favorites from cookie
const favorites = getSortedfavoriteIdsInCookie();
const territoires = getTerritoiresList(territoiresList, favorites);
Expand All @@ -69,8 +68,8 @@ export default function HomeMapCards({
Accès rapide
</Title>
<Text as="p" className="fr-mb-1w">
<i>Vos territoires favoris apparaissent en premiers dans cette liste</i>
<Button onClick={() => clearAllfavoriteIdsInCookie()} variant="text">
<i>Vos territoires favoris apparaissent dans cette liste</i>
<Button onClick={() => {clearAllfavoriteIdsInCookie(); setRefresh(refresh + 1)}} variant="text">
Réinitialiser cette liste
</Button>
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export function Search() {
</Col>
<Col md={3} offsetMd={1}>
<HomeMapCards territoiresList={territoiresList} />
{/* <HomeMapCards /> */}
</Col>
</Row>
</Container>
Expand Down

0 comments on commit 2022c01

Please sign in to comment.