Files
Eric FELIXINE e30ae8ed09 feat(smart-app): implement complete mobile app MVP
- 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
2026-06-01 18:00:35 -04:00

72 lines
3.2 KiB
JavaScript

import { EventEmitter, CodedError, UnavailabilityError } from 'expo-modules-core';
import NotificationsHandlerModule from './NotificationsHandlerModule';
/**
* @hidden
*/
export class NotificationTimeoutError extends CodedError {
info;
constructor(notificationId, notification) {
super('ERR_NOTIFICATION_TIMEOUT', `Notification handling timed out for ID ${notificationId}.`);
this.info = { id: notificationId, notification };
}
}
// Web uses SyntheticEventEmitter
const notificationEmitter = new EventEmitter(NotificationsHandlerModule);
const handleNotificationEventName = 'onHandleNotification';
const handleNotificationTimeoutEventName = 'onHandleNotificationTimeout';
let handleSubscription = null;
let handleTimeoutSubscription = null;
/**
* When a notification is received while the app is running, using this function you can set a callback that will decide
* whether the notification should be shown to the user or not.
*
* When a notification is received, `handleNotification` is called with the incoming notification as an argument.
* The function should respond with a behavior object within 3 seconds, otherwise, the notification will be discarded.
* If the notification is handled successfully, `handleSuccess` is called with the identifier of the notification,
* otherwise (or on timeout) `handleError` will be called.
*
* The default behavior when the handler is not set or does not respond in time is not to show the notification.
* @param handler A single parameter which should be either `null` (if you want to clear the handler) or a [`NotificationHandler`](#notificationhandler) object.
*
* @example Implementing a notification handler that always shows the notification when it is received.
* ```jsx
* import * as Notifications from 'expo-notifications';
*
* Notifications.setNotificationHandler({
* handleNotification: async () => ({
* shouldShowAlert: true,
* shouldPlaySound: false,
* shouldSetBadge: false,
* }),
* });
* ```
* @header inForeground
*/
export function setNotificationHandler(handler) {
if (handleSubscription) {
handleSubscription.remove();
handleSubscription = null;
}
if (handleTimeoutSubscription) {
handleTimeoutSubscription.remove();
handleTimeoutSubscription = null;
}
if (handler) {
handleSubscription = notificationEmitter.addListener(handleNotificationEventName, async ({ id, notification }) => {
if (!NotificationsHandlerModule.handleNotificationAsync) {
handler.handleError?.(id, new UnavailabilityError('Notifications', 'handleNotificationAsync'));
return;
}
try {
const behavior = await handler.handleNotification(notification);
await NotificationsHandlerModule.handleNotificationAsync(id, behavior);
handler.handleSuccess?.(id);
}
catch (error) {
handler.handleError?.(id, error);
}
});
handleTimeoutSubscription = notificationEmitter.addListener(handleNotificationTimeoutEventName, ({ id, notification }) => handler.handleError?.(id, new NotificationTimeoutError(id, notification)));
}
}
//# sourceMappingURL=NotificationsHandler.js.map