about summary refs log tree commit diff
path: root/src/components/dialogs/Context.tsx
blob: c9dff9a99956fd3e3fd06272859d6ff542839f05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react'

import * as Dialog from '#/components/Dialog'

type Control = Dialog.DialogOuterProps['control']

type ControlsContext = {
  mutedWordsDialogControl: Control
  signinDialogControl: Control
}

const ControlsContext = React.createContext({
  mutedWordsDialogControl: {} as Control,
  signinDialogControl: {} as Control,
})

export function useGlobalDialogsControlContext() {
  return React.useContext(ControlsContext)
}

export function Provider({children}: React.PropsWithChildren<{}>) {
  const mutedWordsDialogControl = Dialog.useDialogControl()
  const signinDialogControl = Dialog.useDialogControl()
  const ctx = React.useMemo<ControlsContext>(
    () => ({mutedWordsDialogControl, signinDialogControl}),
    [mutedWordsDialogControl, signinDialogControl],
  )

  return (
    <ControlsContext.Provider value={ctx}>{children}</ControlsContext.Provider>
  )
}