'use client'; import * as React from 'react'; import type { Label, Thread } from './types'; function noop(): void { return undefined; } export interface MailContextValue { labels: Label[]; threads: Thread[]; currentLabelId: string; openDesktopSidebar: boolean; setOpenDesktopSidebar: React.Dispatch>; openMobileSidebar: boolean; setOpenMobileSidebar: React.Dispatch>; openCompose: boolean; setOpenCompose: React.Dispatch>; } export const MailContext = React.createContext({ labels: [], threads: [], currentLabelId: 'inbox', openDesktopSidebar: true, setOpenDesktopSidebar: noop, openMobileSidebar: true, setOpenMobileSidebar: noop, openCompose: false, setOpenCompose: noop, }); export interface MailProviderProps { children: React.ReactNode; labels: Label[]; threads: Thread[]; currentLabelId: string; } export function MailProvider({ children, labels: initialLabels = [], threads: initialThreads = [], currentLabelId, }: MailProviderProps): React.JSX.Element { const [labels, setLabels] = React.useState([]); const [threads, setThreads] = React.useState([]); const [openDesktopSidebar, setOpenDesktopSidebar] = React.useState(true); const [openMobileSidebar, setOpenMobileSidebar] = React.useState(false); const [openCompose, setOpenCompose] = React.useState(false); React.useEffect((): void => { setLabels(initialLabels); }, [initialLabels]); React.useEffect((): void => { setThreads(initialThreads); }, [initialThreads]); return ( {children} ); }