persistance

pull/27/head
accius 4 days ago
parent a5c6aced33
commit b1bad8a893

@ -1829,23 +1829,29 @@
const storedSettings = getStoredMapSettings(); const storedSettings = getStoredMapSettings();
const [mapStyle, setMapStyle] = useState(storedSettings.mapStyle || 'dark'); const [mapStyle, setMapStyle] = useState(storedSettings.mapStyle || 'dark');
const [mapView, setMapView] = useState({
center: storedSettings.center || [20, 0],
zoom: storedSettings.zoom || 2.5
});
// Save map style to localStorage when changed // Save map settings to localStorage when changed
useEffect(() => { useEffect(() => {
try { try {
localStorage.setItem('openhamclock_mapSettings', JSON.stringify({ localStorage.setItem('openhamclock_mapSettings', JSON.stringify({
mapStyle mapStyle,
center: mapView.center,
zoom: mapView.zoom
})); }));
} catch (e) { console.error('Failed to save map settings:', e); } } catch (e) { console.error('Failed to save map settings:', e); }
}, [mapStyle]); }, [mapStyle, mapView]);
// Initialize map // Initialize map
useEffect(() => { useEffect(() => {
if (!mapRef.current || mapInstanceRef.current) return; if (!mapRef.current || mapInstanceRef.current) return;
const map = L.map(mapRef.current, { const map = L.map(mapRef.current, {
center: [20, 0], center: mapView.center,
zoom: 2.5, zoom: mapView.zoom,
minZoom: 2.3, minZoom: 2.3,
maxZoom: 18, maxZoom: 18,
worldCopyJump: true, worldCopyJump: true,
@ -1892,6 +1898,13 @@
onDXChange({ lat: e.latlng.lat, lon: e.latlng.lng }); onDXChange({ lat: e.latlng.lat, lon: e.latlng.lng });
} }
}); });
// Save map view when user pans or zooms
map.on('moveend', () => {
const center = map.getCenter();
const zoom = map.getZoom();
setMapView({ center: [center.lat, center.lng], zoom });
});
mapInstanceRef.current = map; mapInstanceRef.current = map;
@ -3571,7 +3584,26 @@
const [currentTime, setCurrentTime] = useState(new Date()); const [currentTime, setCurrentTime] = useState(new Date());
const [startTime] = useState(Date.now()); const [startTime] = useState(Date.now());
const [uptime, setUptime] = useState('0d 0h 0m'); const [uptime, setUptime] = useState('0d 0h 0m');
const [dxLocation, setDxLocation] = useState(config.defaultDX);
// DX Location with localStorage persistence
const [dxLocation, setDxLocation] = useState(() => {
try {
const stored = localStorage.getItem('openhamclock_dxLocation');
if (stored) {
const parsed = JSON.parse(stored);
if (parsed.lat && parsed.lon) return parsed;
}
} catch (e) {}
return config.defaultDX;
});
// Save DX location when changed
useEffect(() => {
try {
localStorage.setItem('openhamclock_dxLocation', JSON.stringify(dxLocation));
} catch (e) { console.error('Failed to save DX location:', e); }
}, [dxLocation]);
const [showSettings, setShowSettings] = useState(false); const [showSettings, setShowSettings] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false);

Loading…
Cancel
Save

Powered by TurnKey Linux.