- App.tsx: full navigation (Auth stack + Main tabs with 5 screens) - Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen - HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors - MapScreen: interactive map with layer toggles (6 layers) - MarketplaceScreen: categories (6), products (5), search - ChatScreen: AI chat with quick prompts (4), bot responses - ProfileScreen: user info, stats, menu (9 items), logout - AlertsScreen: alert list with severity, acknowledge - SensorsScreen: sensor list with type filters (6 types), search - ZonesScreen: zone cards with stats - SettingsScreen: language picker (FR/EN/ES/DE), privacy, about - Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n - Hooks: useSensors, useAlerts, useNotifications, useLocation - Components: Card, Button, LoadingSpinner, ErrorBoundary, Header - Services: iotService, notificationService (with axios API client) - Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN) - Theme: colors.ts with full design system (Blue Ocean palette) - Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
// Smart App City — Formatters utility
|
|
|
|
export const formatters = {
|
|
temperature: (value: number, unit: string = '°C') => `${value.toFixed(1)}${unit}`,
|
|
humidity: (value: number) => `${value}%`,
|
|
aqi: (value: number) => {
|
|
if (value <= 50) return { label: 'Bon', color: '#2E7D32' };
|
|
if (value <= 100) return { label: 'Modéré', color: '#F57C00' };
|
|
if (value <= 150) return { label: 'Mauvais', color: '#D32F2F' };
|
|
return { label: 'Dangereux', color: '#7B1FA2' };
|
|
},
|
|
noise: (value: number) => {
|
|
if (value <= 40) return { label: 'Silencieux', color: '#2E7D32' };
|
|
if (value <= 55) return { label: 'Normal', color: '#0288D1' };
|
|
if (value <= 70) return { label: 'Bruyant', color: '#F57C00' };
|
|
return { label: 'Très bruyant', color: '#D32F2F' };
|
|
},
|
|
date: (date: string | Date, locale: string = 'fr-FR') => {
|
|
const d = new Date(date);
|
|
return d.toLocaleDateString(locale, {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
});
|
|
},
|
|
time: (date: string | Date) => {
|
|
const d = new Date(date);
|
|
return d.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
|
|
},
|
|
relativeTime: (date: string | Date) => {
|
|
const d = new Date(date);
|
|
const now = new Date();
|
|
const diffMs = now.getTime() - d.getTime();
|
|
const diffMins = Math.floor(diffMs / 60000);
|
|
const diffHours = Math.floor(diffMs / 3600000);
|
|
const diffDays = Math.floor(diffMs / 86400000);
|
|
|
|
if (diffMins < 1) return "À l'instant";
|
|
if (diffMins < 60) return `Il y a ${diffMins} min`;
|
|
if (diffHours < 24) return `Il y a ${diffHours}h`;
|
|
if (diffDays < 7) return `Il y a ${diffDays}j`;
|
|
return d.toLocaleDateString('fr-FR', { day: '2-digit', month: '2-digit' });
|
|
},
|
|
currency: (value: number, currency: string = 'EUR') =>
|
|
new Intl.NumberFormat('fr-FR', { style: 'currency', currency }).format(value),
|
|
};
|