From 5e9f1094a50bbcdd514e958dcd67d0f0a844589d Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Fri, 12 Dec 2025 20:30:44 +0100 Subject: feat: implement favourites management, add recent places functionality, and enhance planner features --- src/frontend/app/data/SpecialPlacesProvider.ts | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/frontend/app/data/SpecialPlacesProvider.ts (limited to 'src/frontend/app/data') diff --git a/src/frontend/app/data/SpecialPlacesProvider.ts b/src/frontend/app/data/SpecialPlacesProvider.ts new file mode 100644 index 0000000..2e3be68 --- /dev/null +++ b/src/frontend/app/data/SpecialPlacesProvider.ts @@ -0,0 +1,78 @@ +import { REGION_DATA } from "~/config/RegionConfig"; + +export interface SpecialPlace { + name: string; + type: "stop" | "address"; + stopId?: string; + address?: string; + latitude?: number; + longitude?: number; +} + +const STORAGE_KEY_HOME = `specialPlace_home_${REGION_DATA.id}`; +const STORAGE_KEY_WORK = `specialPlace_work_${REGION_DATA.id}`; + +function getHome(): SpecialPlace | null { + try { + const raw = localStorage.getItem(STORAGE_KEY_HOME); + if (raw) { + return JSON.parse(raw) as SpecialPlace; + } + } catch (error) { + console.error("Error reading home location:", error); + } + return null; +} + +function setHome(place: SpecialPlace): void { + try { + localStorage.setItem(STORAGE_KEY_HOME, JSON.stringify(place)); + } catch (error) { + console.error("Error saving home location:", error); + } +} + +function removeHome(): void { + try { + localStorage.removeItem(STORAGE_KEY_HOME); + } catch (error) { + console.error("Error removing home location:", error); + } +} + +function getWork(): SpecialPlace | null { + try { + const raw = localStorage.getItem(STORAGE_KEY_WORK); + if (raw) { + return JSON.parse(raw) as SpecialPlace; + } + } catch (error) { + console.error("Error reading work location:", error); + } + return null; +} + +function setWork(place: SpecialPlace): void { + try { + localStorage.setItem(STORAGE_KEY_WORK, JSON.stringify(place)); + } catch (error) { + console.error("Error saving work location:", error); + } +} + +function removeWork(): void { + try { + localStorage.removeItem(STORAGE_KEY_WORK); + } catch (error) { + console.error("Error removing work location:", error); + } +} + +export default { + getHome, + setHome, + removeHome, + getWork, + setWork, + removeWork, +}; -- cgit v1.3