1 import type { ReactNode } from 'react';
2 import { createContext, useContext } from 'react';
4 import type { ThemeColor } from '@proton/colors/types';
5 import MailQuickSettingsReminderContextProvider from '@proton/components/containers/drawer/MailQuickSettingsReminderContextProvider';
6 import useConfig from '@proton/components/hooks/useConfig';
7 import useRecoveryNotification from '@proton/components/hooks/useRecoveryNotification';
8 import { APPS } from '@proton/shared/lib/constants';
9 import isTruthy from '@proton/utils/isTruthy';
12 * Quick settings are now part of the drawer.
13 * Some elements might trigger the display of a dot on the quick settings button.
14 * Once the notification has been seen by the user, the dot needs to disappear on the button.
15 * The role of this context is keep track of these values correctly across the application,
16 * because the value might change after a user action within the drawer, involving a change on the setting button
18 export const QuickSettingsRemindersContext = createContext<{
19 reminders: ThemeColor[];
22 export default function useQuickSettingsReminders() {
23 const quickSettingsNotificationContext = useContext(QuickSettingsRemindersContext);
25 if (!quickSettingsNotificationContext) {
26 throw new Error('Quick Settings reminders provider not initialized');
29 const { reminders } = quickSettingsNotificationContext;
34 export const QuickSettingsRemindersProvider = ({ children }: { children: ReactNode }) => {
35 const { APP_NAME } = useConfig();
37 const recoveryNotification = useRecoveryNotification(false, true);
39 const reminders: ThemeColor[] = [recoveryNotification?.color].filter(isTruthy);
42 * Need to create a different context per app if some reminders are app specific
44 if (APP_NAME === APPS.PROTONMAIL) {
46 <MailQuickSettingsReminderContextProvider defaultReminders={reminders}>
48 </MailQuickSettingsReminderContextProvider>
53 <QuickSettingsRemindersContext.Provider value={{ reminders }}>
55 </QuickSettingsRemindersContext.Provider>