Move to global context
This commit is contained in:
@@ -105,7 +105,6 @@ import TopicScreen from '#/screens/Topic'
|
|||||||
import {VideoFeed} from '#/screens/VideoFeed'
|
import {VideoFeed} from '#/screens/VideoFeed'
|
||||||
import {useTheme} from '#/alf'
|
import {useTheme} from '#/alf'
|
||||||
import {
|
import {
|
||||||
EmailDialog,
|
|
||||||
EmailDialogScreenID,
|
EmailDialogScreenID,
|
||||||
useEmailDialogControl,
|
useEmailDialogControl,
|
||||||
} from '#/components/dialogs/EmailDialog'
|
} from '#/components/dialogs/EmailDialog'
|
||||||
@@ -773,7 +772,6 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) {
|
|||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
<EmailDialog control={emailDialogControl} />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {createContext, useContext, useMemo, useState} from 'react'
|
import {createContext, useContext, useMemo, useState} from 'react'
|
||||||
|
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
|
import {type Screen} from '#/components/dialogs/EmailDialog/types'
|
||||||
|
|
||||||
type Control = Dialog.DialogControlProps
|
type Control = Dialog.DialogControlProps
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ type ControlsContext = {
|
|||||||
mutedWordsDialogControl: Control
|
mutedWordsDialogControl: Control
|
||||||
signinDialogControl: Control
|
signinDialogControl: Control
|
||||||
inAppBrowserConsentControl: StatefulControl<string>
|
inAppBrowserConsentControl: StatefulControl<string>
|
||||||
|
emailDialogControl: StatefulControl<Screen>
|
||||||
}
|
}
|
||||||
|
|
||||||
const ControlsContext = createContext<ControlsContext | null>(null)
|
const ControlsContext = createContext<ControlsContext | null>(null)
|
||||||
@@ -33,14 +35,21 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
const mutedWordsDialogControl = Dialog.useDialogControl()
|
const mutedWordsDialogControl = Dialog.useDialogControl()
|
||||||
const signinDialogControl = Dialog.useDialogControl()
|
const signinDialogControl = Dialog.useDialogControl()
|
||||||
const inAppBrowserConsentControl = useStatefulDialogControl<string>()
|
const inAppBrowserConsentControl = useStatefulDialogControl<string>()
|
||||||
|
const emailDialogControl = useStatefulDialogControl<Screen>()
|
||||||
|
|
||||||
const ctx = useMemo<ControlsContext>(
|
const ctx = useMemo<ControlsContext>(
|
||||||
() => ({
|
() => ({
|
||||||
mutedWordsDialogControl,
|
mutedWordsDialogControl,
|
||||||
signinDialogControl,
|
signinDialogControl,
|
||||||
inAppBrowserConsentControl,
|
inAppBrowserConsentControl,
|
||||||
|
emailDialogControl,
|
||||||
}),
|
}),
|
||||||
[mutedWordsDialogControl, signinDialogControl, inAppBrowserConsentControl],
|
[
|
||||||
|
mutedWordsDialogControl,
|
||||||
|
signinDialogControl,
|
||||||
|
inAppBrowserConsentControl,
|
||||||
|
emailDialogControl,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ import {msg} from '@lingui/macro'
|
|||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {
|
import {type StatefulControl} from '#/components/dialogs/Context'
|
||||||
type StatefulControl,
|
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
||||||
useStatefulDialogControl,
|
|
||||||
} from '#/components/dialogs/Context'
|
|
||||||
import {useAccountEmailState} from '#/components/dialogs/EmailDialog/data/useAccountEmailState'
|
import {useAccountEmailState} from '#/components/dialogs/EmailDialog/data/useAccountEmailState'
|
||||||
import {Manage2FA} from '#/components/dialogs/EmailDialog/screens/Manage2FA'
|
import {Manage2FA} from '#/components/dialogs/EmailDialog/screens/Manage2FA'
|
||||||
import {Update} from '#/components/dialogs/EmailDialog/screens/Update'
|
import {Update} from '#/components/dialogs/EmailDialog/screens/Update'
|
||||||
@@ -14,33 +12,33 @@ import {VerificationReminder} from '#/components/dialogs/EmailDialog/screens/Ver
|
|||||||
import {Verify} from '#/components/dialogs/EmailDialog/screens/Verify'
|
import {Verify} from '#/components/dialogs/EmailDialog/screens/Verify'
|
||||||
import {type Screen, ScreenID} from '#/components/dialogs/EmailDialog/types'
|
import {type Screen, ScreenID} from '#/components/dialogs/EmailDialog/types'
|
||||||
|
|
||||||
export {useDialogControl} from '#/components/Dialog'
|
|
||||||
export type {Screen} from '#/components/dialogs/EmailDialog/types'
|
export type {Screen} from '#/components/dialogs/EmailDialog/types'
|
||||||
export {ScreenID as EmailDialogScreenID} from '#/components/dialogs/EmailDialog/types'
|
export {ScreenID as EmailDialogScreenID} from '#/components/dialogs/EmailDialog/types'
|
||||||
|
|
||||||
export function useEmailDialogControl() {
|
export function useEmailDialogControl() {
|
||||||
return useStatefulDialogControl<Screen>()
|
return useGlobalDialogsControlContext().emailDialogControl
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EmailDialog({control}: {control: StatefulControl<Screen>}) {
|
export function EmailDialog() {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
const emailDialogControl = useEmailDialogControl()
|
||||||
const {isEmailVerified} = useAccountEmailState()
|
const {isEmailVerified} = useAccountEmailState()
|
||||||
const onClose = useCallback(() => {
|
const onClose = useCallback(() => {
|
||||||
if (!isEmailVerified) {
|
if (!isEmailVerified) {
|
||||||
if (control.value?.id === ScreenID.Verify) {
|
if (emailDialogControl.value?.id === ScreenID.Verify) {
|
||||||
control.value.onCloseWithoutVerifying?.()
|
emailDialogControl.value.onCloseWithoutVerifying?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [isEmailVerified, control])
|
}, [isEmailVerified, emailDialogControl])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Outer control={control.control} onClose={onClose}>
|
<Dialog.Outer control={emailDialogControl.control} onClose={onClose}>
|
||||||
<Dialog.Handle />
|
<Dialog.Handle />
|
||||||
|
|
||||||
<Dialog.ScrollableInner
|
<Dialog.ScrollableInner
|
||||||
label={_(msg`Make adjustments to your account email settings`)}
|
label={_(msg`Make adjustments to your account email settings`)}
|
||||||
style={[{maxWidth: 400}]}>
|
style={[{maxWidth: 400}]}>
|
||||||
<Inner control={control} />
|
<Inner control={emailDialogControl} />
|
||||||
<Dialog.Close />
|
<Dialog.Close />
|
||||||
</Dialog.ScrollableInner>
|
</Dialog.ScrollableInner>
|
||||||
</Dialog.Outer>
|
</Dialog.Outer>
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import {useSetMinimalShellMode} from '#/state/shell'
|
|||||||
import {MessagesList} from '#/screens/Messages/components/MessagesList'
|
import {MessagesList} from '#/screens/Messages/components/MessagesList'
|
||||||
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
||||||
import {
|
import {
|
||||||
EmailDialog,
|
|
||||||
EmailDialogScreenID,
|
EmailDialogScreenID,
|
||||||
useEmailDialogControl,
|
useEmailDialogControl,
|
||||||
} from '#/components/dialogs/EmailDialog'
|
} from '#/components/dialogs/EmailDialog'
|
||||||
@@ -229,7 +228,6 @@ function InnerReady({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<EmailDialog control={emailDialogControl} />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {atoms as a, useTheme} from '#/alf'
|
|||||||
import {useDialogControl} from '#/components/Dialog'
|
import {useDialogControl} from '#/components/Dialog'
|
||||||
import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings'
|
import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings'
|
||||||
import {
|
import {
|
||||||
EmailDialog,
|
|
||||||
EmailDialogScreenID,
|
EmailDialogScreenID,
|
||||||
useEmailDialogControl,
|
useEmailDialogControl,
|
||||||
} from '#/components/dialogs/EmailDialog'
|
} from '#/components/dialogs/EmailDialog'
|
||||||
@@ -177,7 +176,6 @@ export function AccountSettingsScreen({}: Props) {
|
|||||||
</SettingsList.Container>
|
</SettingsList.Container>
|
||||||
</Layout.Content>
|
</Layout.Content>
|
||||||
|
|
||||||
<EmailDialog control={emailDialogControl} />
|
|
||||||
<BirthDateSettingsDialog control={birthdayControl} />
|
<BirthDateSettingsDialog control={birthdayControl} />
|
||||||
<ChangeHandleDialog control={changeHandleControl} />
|
<ChangeHandleDialog control={changeHandleControl} />
|
||||||
<ExportCarDialog control={exportCarControl} />
|
<ExportCarDialog control={exportCarControl} />
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {useLingui} from '@lingui/react'
|
|||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
import {useDialogControl} from '#/components/Dialog'
|
||||||
import {
|
import {
|
||||||
EmailDialog,
|
|
||||||
EmailDialogScreenID,
|
EmailDialogScreenID,
|
||||||
useEmailDialogControl,
|
useEmailDialogControl,
|
||||||
} from '#/components/dialogs/EmailDialog'
|
} from '#/components/dialogs/EmailDialog'
|
||||||
@@ -27,7 +26,6 @@ export function Email2FAToggle() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DisableEmail2FADialog control={disableDialogControl} />
|
<DisableEmail2FADialog control={disableDialogControl} />
|
||||||
<EmailDialog control={emailDialogControl} />
|
|
||||||
<SettingsList.BadgeButton
|
<SettingsList.BadgeButton
|
||||||
label={
|
label={
|
||||||
currentAccount?.emailAuthFactor ? _(msg`Change`) : _(msg`Enable`)
|
currentAccount?.emailAuthFactor ? _(msg`Change`) : _(msg`Enable`)
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ import {UserAvatar} from '#/view/com/util/UserAvatar'
|
|||||||
import {atoms as a, native, useTheme} from '#/alf'
|
import {atoms as a, native, useTheme} from '#/alf'
|
||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
import {
|
import {
|
||||||
EmailDialog,
|
|
||||||
EmailDialogScreenID,
|
EmailDialogScreenID,
|
||||||
useEmailDialogControl,
|
useEmailDialogControl,
|
||||||
} from '#/components/dialogs/EmailDialog'
|
} from '#/components/dialogs/EmailDialog'
|
||||||
@@ -633,7 +632,6 @@ export const ComposePost = ({
|
|||||||
const isWebFooterSticky = !isNative && thread.posts.length > 1
|
const isWebFooterSticky = !isNative && thread.posts.length > 1
|
||||||
return (
|
return (
|
||||||
<BottomSheetPortalProvider>
|
<BottomSheetPortalProvider>
|
||||||
<EmailDialog control={emailDialogControl} />
|
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
testID="composePostView"
|
testID="composePostView"
|
||||||
behavior={isIOS ? 'padding' : 'height'}
|
behavior={isIOS ? 'padding' : 'height'}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import {ModalsContainer} from '#/view/com/modals/Modal'
|
|||||||
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
||||||
import {atoms as a, select, useTheme} from '#/alf'
|
import {atoms as a, select, useTheme} from '#/alf'
|
||||||
import {setSystemUITheme} from '#/alf/util/systemUI'
|
import {setSystemUITheme} from '#/alf/util/systemUI'
|
||||||
|
import {EmailDialog} from '#/components/dialogs/EmailDialog'
|
||||||
import {InAppBrowserConsentDialog} from '#/components/dialogs/InAppBrowserConsent'
|
import {InAppBrowserConsentDialog} from '#/components/dialogs/InAppBrowserConsent'
|
||||||
import {MutedWordsDialog} from '#/components/dialogs/MutedWords'
|
import {MutedWordsDialog} from '#/components/dialogs/MutedWords'
|
||||||
import {SigninDialog} from '#/components/dialogs/Signin'
|
import {SigninDialog} from '#/components/dialogs/Signin'
|
||||||
@@ -152,6 +153,7 @@ function ShellInner() {
|
|||||||
<ModalsContainer />
|
<ModalsContainer />
|
||||||
<MutedWordsDialog />
|
<MutedWordsDialog />
|
||||||
<SigninDialog />
|
<SigninDialog />
|
||||||
|
<EmailDialog />
|
||||||
<InAppBrowserConsentDialog />
|
<InAppBrowserConsentDialog />
|
||||||
<Lightbox />
|
<Lightbox />
|
||||||
<PortalOutlet />
|
<PortalOutlet />
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {RemoveScrollBar} from 'react-remove-scroll-bar'
|
|||||||
import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
||||||
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
||||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||||
import {NavigationProp} from '#/lib/routes/types'
|
import {type NavigationProp} from '#/lib/routes/types'
|
||||||
import {colors} from '#/lib/styles'
|
import {colors} from '#/lib/styles'
|
||||||
import {useIsDrawerOpen, useSetDrawerOpen} from '#/state/shell'
|
import {useIsDrawerOpen, useSetDrawerOpen} from '#/state/shell'
|
||||||
import {useComposerKeyboardShortcut} from '#/state/shell/composer/useComposerKeyboardShortcut'
|
import {useComposerKeyboardShortcut} from '#/state/shell/composer/useComposerKeyboardShortcut'
|
||||||
@@ -17,6 +17,7 @@ import {Lightbox} from '#/view/com/lightbox/Lightbox'
|
|||||||
import {ModalsContainer} from '#/view/com/modals/Modal'
|
import {ModalsContainer} from '#/view/com/modals/Modal'
|
||||||
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
||||||
import {atoms as a, select, useTheme} from '#/alf'
|
import {atoms as a, select, useTheme} from '#/alf'
|
||||||
|
import {EmailDialog} from '#/components/dialogs/EmailDialog'
|
||||||
import {MutedWordsDialog} from '#/components/dialogs/MutedWords'
|
import {MutedWordsDialog} from '#/components/dialogs/MutedWords'
|
||||||
import {SigninDialog} from '#/components/dialogs/Signin'
|
import {SigninDialog} from '#/components/dialogs/Signin'
|
||||||
import {Outlet as PortalOutlet} from '#/components/Portal'
|
import {Outlet as PortalOutlet} from '#/components/Portal'
|
||||||
@@ -67,6 +68,7 @@ function ShellInner() {
|
|||||||
<ModalsContainer />
|
<ModalsContainer />
|
||||||
<MutedWordsDialog />
|
<MutedWordsDialog />
|
||||||
<SigninDialog />
|
<SigninDialog />
|
||||||
|
<EmailDialog />
|
||||||
<Lightbox />
|
<Lightbox />
|
||||||
<PortalOutlet />
|
<PortalOutlet />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user