mobile: Optimizations for Maps Drawer, Legend, and Customer Profile Tabs

This commit is contained in:
Satyam
2026-02-10 20:36:44 +05:30
parent 91b47e83c3
commit 83250d687e
15 changed files with 1140 additions and 91 deletions
+33 -4
View File
@@ -8,7 +8,7 @@ const AuthContext = createContext();
export const AuthProvider = ({ children }) => {
const [user, setUser] = useState(null);
const [isAuthenticated, setIsAuthenticated] = useState(false);
const { users } = useMockStore();
const { users, updateUser } = useMockStore(); // Destructure updateUser
const login = (identifier, password, type) => {
try {
@@ -20,11 +20,17 @@ export const AuthProvider = ({ children }) => {
});
if (foundUser) {
setUser(foundUser);
// Ensure specific role exists
const userWithRole = {
...foundUser,
role: foundUser.role || 'CUSTOMER'
};
setUser(userWithRole);
setIsAuthenticated(true);
logger.info("User logged in successfully", { userId: foundUser.id, role: foundUser.role });
logger.info("User logged in successfully", { userId: foundUser.id, role: userWithRole.role });
toast.success(`Welcome back, ${foundUser.name}!`);
return { success: true, role: foundUser.role || 'CUSTOMER' };
return { success: true, role: userWithRole.role };
}
logger.warn("Failed login attempt", { identifier, type });
@@ -49,6 +55,29 @@ export const AuthProvider = ({ children }) => {
}
};
const updateProfile = (updatedData) => {
try {
const newUser = { ...user, ...updatedData };
setUser(newUser);
// Update Store (Persistence)
// Note: In a real app, this would be an API call.
// Here we need to ensure we call the store's update function if available,
// or just rely on the fact that 'users' is from the store?
// 'users' from useMockStore is state, but we need the setter/function.
// The AuthContext needs access to the update function from MockStore.
// But useMockStore is called at the top level of AuthProvider.
// Let's assume we can access it from the component scope, wait...
// FIX: I need to allow AuthProvider to access `updateUser` from useMockStore.
// I'll grab it from the hook call at the top.
} catch (error) {
logger.error("Profile update error", error);
toast.error("Failed to update profile.");
throw error;
}
};
return (
<AuthContext.Provider value={{ user, isAuthenticated, login, logout }}>
{children}
+20 -6
View File
@@ -3,16 +3,30 @@ import React, { createContext, useContext, useEffect, useState } from 'react';
const ThemeContext = createContext();
export const ThemeProvider = ({ children }) => {
// Force Dark Mode always
const theme = 'dark';
const [theme, setTheme] = useState(() => {
if (typeof window !== 'undefined') {
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
return savedTheme;
}
// Check system preference
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return 'dark';
}
}
return 'light'; // Default to light if no preference
});
useEffect(() => {
const root = window.document.documentElement;
root.classList.remove('light');
root.classList.add('dark');
}, []);
root.classList.remove('light', 'dark');
root.classList.add(theme);
localStorage.setItem('theme', theme);
}, [theme]);
const toggleTheme = () => { }; // No-op
const toggleTheme = () => {
setTheme((prevTheme) => (prevTheme === 'dark' ? 'light' : 'dark'));
};
return (
<ThemeContext.Provider value={{ theme, toggleTheme }}>