aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/data/SpecialPlacesProvider.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app/data/SpecialPlacesProvider.ts')
-rw-r--r--src/frontend/app/data/SpecialPlacesProvider.ts78
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,
+};