# Mobile Settings Implementation Guide
## Overview
Complete implementation guide for creating a full-featured mobile settings screen that matches desktop functionality. This addresses the critical gap where desktop has comprehensive settings but mobile only has a placeholder.
## Current State Analysis
### Desktop Settings (Full Implementation)
**File**: `/home/egullickson/motovaultpro/frontend/src/pages/SettingsPage.tsx`
**Features**:
- Account management section
- Notifications settings
- Appearance & Units (dark mode, metric/imperial)
- Data export and management
- Account actions (logout, delete account)
### Mobile Settings (Placeholder Only)
**File**: `frontend/src/App.tsx` (lines 113-122)
**Current Implementation**:
```tsx
const SettingsScreen = () => (
Settings
Coming soon - App settings and preferences
);
```
## Implementation Strategy
### Step 1: Create Mobile Settings Directory Structure
Create dedicated mobile settings components following existing patterns:
```
frontend/src/features/settings/
├── mobile/
│ ├── MobileSettingsScreen.tsx # Main settings screen
│ ├── AccountSection.tsx # Account management
│ ├── NotificationsSection.tsx # Notification preferences
│ ├── AppearanceSection.tsx # Dark mode & units
│ ├── DataSection.tsx # Export & data management
│ └── AccountActionsSection.tsx # Logout & delete account
└── hooks/
├── useSettings.ts # Settings state management
└── useSettingsPersistence.ts # Settings persistence
```
### Step 2: Implement Mobile Settings Screen Component
**File**: `frontend/src/features/settings/mobile/MobileSettingsScreen.tsx`
```tsx
import React from 'react';
import { GlassCard, MobileContainer } from '../../../shared-minimal/components/mobile';
import { AccountSection } from './AccountSection';
import { NotificationsSection } from './NotificationsSection';
import { AppearanceSection } from './AppearanceSection';
import { DataSection } from './DataSection';
import { AccountActionsSection } from './AccountActionsSection';
export const MobileSettingsScreen: React.FC = () => {
return (
{/* Bottom padding for nav */}
Settings
Manage your account and preferences
);
};
```
### Step 3: Implement Settings Sections
#### Account Section Component
**File**: `frontend/src/features/settings/mobile/AccountSection.tsx`
```tsx
import React from 'react';
import { useAuth0 } from '@auth0/auth0-react';
import { GlassCard } from '../../../shared-minimal/components/mobile';
export const AccountSection: React.FC = () => {
const { user } = useAuth0();
return (
Account
{user?.name}
{user?.email}
Member since {new Date(user?.updated_at || '').toLocaleDateString()}
);
};
```
#### Appearance Section Component
**File**: `frontend/src/features/settings/mobile/AppearanceSection.tsx`
```tsx
import React from 'react';
import { GlassCard } from '../../../shared-minimal/components/mobile';
import { useSettings } from '../hooks/useSettings';
export const AppearanceSection: React.FC = () => {
const { settings, updateSetting } = useSettings();
const toggleDarkMode = () => {
updateSetting('darkMode', !settings.darkMode);
};
const toggleUnitSystem = () => {
updateSetting('unitSystem', settings.unitSystem === 'imperial' ? 'metric' : 'imperial');
};
return (
Appearance & Units
{/* Dark Mode Toggle */}
Dark Mode
Switch to dark theme
{/* Unit System Toggle */}
Unit System
Currently using {settings.unitSystem === 'imperial' ? 'Miles & Gallons' : 'Kilometers & Liters'}
{settings.unitSystem === 'imperial' ? 'Switch to Metric' : 'Switch to Imperial'}
);
};
```
#### Account Actions Section Component
**File**: `frontend/src/features/settings/mobile/AccountActionsSection.tsx`
```tsx
import React, { useState } from 'react';
import { useAuth0 } from '@auth0/auth0-react';
import { GlassCard } from '../../../shared-minimal/components/mobile';
export const AccountActionsSection: React.FC = () => {
const { logout } = useAuth0();
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const handleLogout = () => {
logout({
logoutParams: {
returnTo: window.location.origin
}
});
};
const handleDeleteAccount = () => {
// Implementation for account deletion
setShowDeleteConfirm(false);
// Navigate to account deletion flow
};
return (
Account Actions
Sign Out
setShowDeleteConfirm(true)}
className="w-full py-3 px-4 bg-red-50 text-red-600 rounded-lg text-left font-medium hover:bg-red-100 transition-colors"
>
Delete Account
{/* Delete Confirmation Modal */}
{showDeleteConfirm && (
Delete Account
This action cannot be undone. All your data will be permanently deleted.
setShowDeleteConfirm(false)}
className="flex-1 py-2 px-4 bg-gray-200 text-gray-700 rounded-lg font-medium"
>
Cancel
Delete
)}
);
};
```
### Step 4: Implement Settings State Management
#### Settings Hook
**File**: `frontend/src/features/settings/hooks/useSettings.ts`
```tsx
import { useState, useEffect } from 'react';
import { useSettingsPersistence } from './useSettingsPersistence';
export interface SettingsState {
darkMode: boolean;
unitSystem: 'imperial' | 'metric';
notifications: {
email: boolean;
push: boolean;
maintenance: boolean;
};
}
const defaultSettings: SettingsState = {
darkMode: false,
unitSystem: 'imperial',
notifications: {
email: true,
push: true,
maintenance: true,
},
};
export const useSettings = () => {
const { loadSettings, saveSettings } = useSettingsPersistence();
const [settings, setSettings] = useState(defaultSettings);
useEffect(() => {
const savedSettings = loadSettings();
if (savedSettings) {
setSettings(savedSettings);
}
}, [loadSettings]);
const updateSetting = (
key: K,
value: SettingsState[K]
) => {
const newSettings = { ...settings, [key]: value };
setSettings(newSettings);
saveSettings(newSettings);
};
return {
settings,
updateSetting,
};
};
```
#### Settings Persistence Hook
**File**: `frontend/src/features/settings/hooks/useSettingsPersistence.ts`
```tsx
import { useCallback } from 'react';
import { SettingsState } from './useSettings';
const SETTINGS_STORAGE_KEY = 'motovaultpro-mobile-settings';
export const useSettingsPersistence = () => {
const loadSettings = useCallback((): SettingsState | null => {
try {
const stored = localStorage.getItem(SETTINGS_STORAGE_KEY);
return stored ? JSON.parse(stored) : null;
} catch (error) {
console.error('Error loading settings:', error);
return null;
}
}, []);
const saveSettings = useCallback((settings: SettingsState) => {
try {
localStorage.setItem(SETTINGS_STORAGE_KEY, JSON.stringify(settings));
} catch (error) {
console.error('Error saving settings:', error);
}
}, []);
return {
loadSettings,
saveSettings,
};
};
```
### Step 5: Update App.tsx Integration
**File**: `frontend/src/App.tsx`
Replace the existing placeholder SettingsScreen with:
```tsx
// Import the new component
import { MobileSettingsScreen } from './features/settings/mobile/MobileSettingsScreen';
// Replace the existing SettingsScreen component (around line 113)
const SettingsScreen = MobileSettingsScreen;
```
### Step 6: Integration with Existing Systems
#### Unit System Integration
Ensure mobile settings integrate with existing unit system:
**File**: `frontend/src/shared-minimal/utils/units.ts`
The mobile settings should use the existing unit conversion utilities and persist to the same storage key (`motovaultpro-unit-system`).
#### Zustand Store Integration
**File**: `frontend/src/core/store/index.ts`
Extend the existing store to include settings state if needed for cross-component access.
## Testing Requirements
### Mobile Testing Checklist
- ✅ Settings screen renders correctly on mobile devices
- ✅ All sections (Account, Notifications, Appearance, Data, Actions) function properly
- ✅ Dark mode toggle works and persists
- ✅ Unit system changes work and persist
- ✅ Logout functionality works correctly
- ✅ Account deletion flow works (with confirmation)
- ✅ Settings persist across app restarts
- ✅ Navigation to/from settings maintains context
### Desktop Compatibility Testing
- ✅ Changes don't break existing desktop settings
- ✅ Settings synchronize between mobile and desktop views
- ✅ Unit system changes reflect in both interfaces
- ✅ Authentication flows remain consistent
### Integration Testing
- ✅ Settings integrate properly with existing Auth0 authentication
- ✅ Unit preferences work across all features (vehicles, fuel logs, etc.)
- ✅ Settings state management doesn't conflict with existing Zustand store
- ✅ localStorage persistence works correctly
## Migration Strategy
### Phase 1: Component Creation
1. Create the mobile settings directory structure
2. Implement individual settings section components
3. Create settings hooks for state management
### Phase 2: Integration
1. Replace placeholder in App.tsx
2. Test mobile settings functionality
3. Verify persistence and state management
### Phase 3: Enhancement
1. Add any missing features from desktop version
2. Implement mobile-specific optimizations
3. Ensure full feature parity
## Success Criteria
Upon completion, the mobile settings should:
1. **Feature Parity**: Match all desktop settings functionality
2. **Mobile-Optimized**: Use appropriate mobile UI patterns and components
3. **Persistent**: All settings persist across app restarts
4. **Integrated**: Work seamlessly with existing authentication and state management
5. **Tested**: Pass all mobile and desktop compatibility tests
This implementation will eliminate the critical mobile settings gap and provide a comprehensive settings experience across all platforms.