managarten/memoro/apps/mobile/features/location/LocationContext.tsx
Till-JS e7f5f942f3 chore: initial commit - consolidate 4 projects into monorepo
Projects included:
- maerchenzauber (NestJS backend + Expo mobile + SvelteKit web + Astro landing)
- manacore (Expo mobile + SvelteKit web + Astro landing)
- manadeck (NestJS backend + Expo mobile + SvelteKit web)
- memoro (Expo mobile + SvelteKit web + Astro landing)

This commit preserves the current state before monorepo restructuring.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:38:24 +01:00

55 lines
1.6 KiB
TypeScript

import React, { createContext, useContext, useState, useEffect } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
interface LocationContextType {
saveLocation: boolean;
setSaveLocation: (value: boolean) => Promise<void>;
}
const LocationContext = createContext<LocationContextType | undefined>(undefined);
export const LocationProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [saveLocation, setSaveLocationState] = useState(false);
// Lade die gespeicherte Einstellung beim Start
useEffect(() => {
const loadSavedSetting = async () => {
try {
const savedValue = await AsyncStorage.getItem('saveLocation');
if (savedValue !== null) {
setSaveLocationState(savedValue === 'true');
}
} catch (error) {
console.debug('Fehler beim Laden der Standorteinstellung:', error);
}
};
loadSavedSetting();
}, []);
// Funktion zum Aktualisieren der Einstellung
const setSaveLocation = async (value: boolean) => {
try {
await AsyncStorage.setItem('saveLocation', value.toString());
setSaveLocationState(value);
} catch (error) {
console.debug('Fehler beim Speichern der Standorteinstellung:', error);
}
};
return (
<LocationContext.Provider value={{ saveLocation, setSaveLocation }}>
{children}
</LocationContext.Provider>
);
};
export const useLocation = () => {
const context = useContext(LocationContext);
if (context === undefined) {
throw new Error('useLocation muss innerhalb eines LocationProviders verwendet werden');
}
return context;
};