diff --git a/frontend/src/components/PopUp/SearchPopUp.tsx b/frontend/src/components/PopUp/SearchPopUp.tsx index 4fbd1116..7a4a2ee1 100644 --- a/frontend/src/components/PopUp/SearchPopUp.tsx +++ b/frontend/src/components/PopUp/SearchPopUp.tsx @@ -32,7 +32,9 @@ const SearchPopUp: React.FC = ({ const filterBySearchtxtAndIfInFavorites = (item: MapSelection) => { return ( item.displayName.toLowerCase().includes(searchText.toLowerCase()) && - !currentSearchCache.favourites.some((fav) => fav.id === item.id) + !currentSearchCache.favourites.some((fav) => + fav.coordinates.equals(item.coordinates) + ) ); }; @@ -41,19 +43,24 @@ const SearchPopUp: React.FC = ({ }; // Adds an item to the favourites - const addToFavourites = (item: MapSelection) => { - if (!currentSearchCache.favourites.some((fav) => fav.id === item.id)) { + const addToFavourites = (newLocation: MapSelection) => { + if ( + !currentSearchCache.favourites.some((fav) => + fav.coordinates.equals(newLocation.coordinates) + ) + ) { + const newFav = [...currentSearchCache.favourites, newLocation]; setCurrentSearchCache({ ...currentSearchCache, - favourites: [...currentSearchCache.favourites, item], + favourites: newFav, }); } }; // Removes an item from the favourites - const removeFromFavourites = (itemToRemove: MapSelection) => { + const removeFromFavourites = (locationToRemove: MapSelection) => { const updatedFavorites = currentSearchCache.favourites.filter( - (item) => item.id !== itemToRemove.id + (item) => !item.coordinates.equals(locationToRemove.coordinates) ); setCurrentSearchCache({ ...currentSearchCache, @@ -107,7 +114,7 @@ const SearchPopUp: React.FC = ({ "& .MuiDialog-container": { "& .MuiPaper-root": { width: "100%", - maxWidth: "500px", // Set your width here + maxWidth: "500px", }, }, }} diff --git a/frontend/src/contexts/SearchContext.tsx b/frontend/src/contexts/SearchContext.tsx index c9258f97..bf91f1e3 100644 --- a/frontend/src/contexts/SearchContext.tsx +++ b/frontend/src/contexts/SearchContext.tsx @@ -5,7 +5,6 @@ import React, { createContext, useState, ReactNode } from "react"; // Map Selection Type export type MapSelection = { - id: string; coordinates: LatLng; displayName: string; }; @@ -33,45 +32,37 @@ type SearchContextProviderProps = { const defaultSearchCache: SearchCacheProps = { searchHistory: [ { - id: "1", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 12.0288]), displayName: "Nuremberg", }, { - id: "2", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 13.0288]), displayName: "Munich", }, { - id: "3", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 14.0288]), displayName: "Andreij Sacharow Platz 1, 90402 Nuremberg", }, { - id: "4", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 15.0288]), displayName: "Main train station Nuremberg", }, { - id: "5", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 16.0288]), displayName: "Walter-Meckauer-Street 20", }, { - id: "6", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 17.0288]), displayName: "49°26'46.6\"N 11°04'33.7\"E", }, ], favourites: [ { - id: "1", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 12.0288]), displayName: "Nuremberg", }, { - id: "2", - coordinates: L.latLng([49.5732, 11.0288]), + coordinates: L.latLng([49.5732, 13.0288]), displayName: "Munich", }, ], diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 63f2b74c..15addf8a 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -4,12 +4,15 @@ import App from "./App.tsx"; import "./index.css"; import { TabsContextProvider } from "./contexts/TabsContext.tsx"; import { MapContextProvider } from "./contexts/MapContext.tsx"; +import { SearchContextProvider } from "./contexts/SearchContext.tsx"; ReactDOM.createRoot(document.getElementById("root")!).render( - + + +