Mobile Work
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
|
||||
import { UnitSystem, UnitPreferences } from './units.types';
|
||||
import { safeStorage } from '../utils/safe-storage';
|
||||
import {
|
||||
formatDistanceBySystem,
|
||||
formatVolumeBySystem,
|
||||
@@ -48,18 +49,26 @@ export const UnitsProvider: React.FC<UnitsProviderProps> = ({
|
||||
}) => {
|
||||
const [unitSystem, setUnitSystem] = useState<UnitSystem>(initialSystem);
|
||||
|
||||
// Load unit preference from localStorage on mount
|
||||
// Load unit preference from storage on mount
|
||||
useEffect(() => {
|
||||
const stored = localStorage.getItem('motovaultpro-unit-system');
|
||||
if (stored === 'imperial' || stored === 'metric') {
|
||||
setUnitSystem(stored);
|
||||
try {
|
||||
const stored = safeStorage.getItem('motovaultpro-unit-system');
|
||||
if (stored === 'imperial' || stored === 'metric') {
|
||||
setUnitSystem(stored);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[Units] Failed to load unit system preference:', error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Save unit preference to localStorage when changed
|
||||
|
||||
// Save unit preference to storage when changed
|
||||
const handleSetUnitSystem = (system: UnitSystem) => {
|
||||
setUnitSystem(system);
|
||||
localStorage.setItem('motovaultpro-unit-system', system);
|
||||
try {
|
||||
safeStorage.setItem('motovaultpro-unit-system', system);
|
||||
} catch (error) {
|
||||
console.warn('[Units] Failed to save unit system preference:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// Generate preferences object based on current system
|
||||
|
||||
Reference in New Issue
Block a user