diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-12 20:30:44 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-12 20:30:44 +0100 |
| commit | 5e9f1094a50bbcdd514e958dcd67d0f0a844589d (patch) | |
| tree | 6df6dd2f589d18d60df33b82456305b04c6b8688 /src/frontend/app/data/SpecialPlacesProvider.ts | |
| parent | c3363ee0e3808d826c4e4797ffa7207647435e08 (diff) | |
feat: implement favourites management, add recent places functionality, and enhance planner features
Diffstat (limited to 'src/frontend/app/data/SpecialPlacesProvider.ts')
| -rw-r--r-- | src/frontend/app/data/SpecialPlacesProvider.ts | 78 |
1 files changed, 78 insertions, 0 deletions
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, +}; |
