Dialogs side quest
This commit is contained in:
@@ -1,19 +1,27 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import {useDialogStateContext} from '#/state/dialogs'
|
import {useDialogStateContext} from '#/state/dialogs'
|
||||||
import {DialogContextProps, DialogControlProps} from '#/components/Dialog/types'
|
import {
|
||||||
|
DialogContextProps,
|
||||||
|
DialogControlProps,
|
||||||
|
DialogControlWithRefProps,
|
||||||
|
DialogParams,
|
||||||
|
} from '#/components/Dialog/types'
|
||||||
|
|
||||||
export const Context = React.createContext<DialogContextProps>({
|
export const Context = React.createContext<DialogContextProps<{}>>({
|
||||||
|
params: {},
|
||||||
close: () => {},
|
close: () => {},
|
||||||
})
|
})
|
||||||
|
|
||||||
export function useDialogContext() {
|
export function useDialogContext<Params extends DialogParams>() {
|
||||||
return React.useContext(Context)
|
return React.useContext(Context) as DialogContextProps<Params>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useDialogControl() {
|
export function useDialogControl<
|
||||||
|
Params extends DialogParams,
|
||||||
|
>(): DialogControlWithRefProps<Params> {
|
||||||
const id = React.useId()
|
const id = React.useId()
|
||||||
const control = React.useRef<DialogControlProps>({
|
const control = React.useRef<DialogControlProps<Params>>({
|
||||||
open: () => {},
|
open: () => {},
|
||||||
close: () => {},
|
close: () => {},
|
||||||
})
|
})
|
||||||
@@ -29,7 +37,7 @@ export function useDialogControl() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
ref: control,
|
ref: control,
|
||||||
open: () => control.current.open(),
|
open: (params, options) => control.current.open(params, options),
|
||||||
close: () => control.current.close(),
|
close: () => control.current.close(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
DialogOuterProps,
|
DialogOuterProps,
|
||||||
DialogControlProps,
|
DialogControlProps,
|
||||||
DialogInnerProps,
|
DialogInnerProps,
|
||||||
|
DialogParams,
|
||||||
} from '#/components/Dialog/types'
|
} from '#/components/Dialog/types'
|
||||||
import {Context} from '#/components/Dialog/context'
|
import {Context} from '#/components/Dialog/context'
|
||||||
|
|
||||||
@@ -24,20 +25,28 @@ export * from '#/components/Dialog/types'
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const Input = createInput(BottomSheetTextInput)
|
export const Input = createInput(BottomSheetTextInput)
|
||||||
|
|
||||||
export function Outer({
|
export function Outer<Params extends DialogParams>({
|
||||||
children,
|
children,
|
||||||
control,
|
control,
|
||||||
onClose,
|
onClose,
|
||||||
nativeOptions,
|
nativeOptions,
|
||||||
}: React.PropsWithChildren<DialogOuterProps>) {
|
}: React.PropsWithChildren<DialogOuterProps<Params>>) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const sheet = React.useRef<BottomSheet>(null)
|
const sheet = React.useRef<BottomSheet>(null)
|
||||||
const sheetOptions = nativeOptions?.sheet || {}
|
const sheetOptions = nativeOptions?.sheet || {}
|
||||||
const hasSnapPoints = !!sheetOptions.snapPoints
|
const hasSnapPoints = !!sheetOptions.snapPoints
|
||||||
|
const [params, setParams] = React.useState({})
|
||||||
|
|
||||||
const open = React.useCallback<DialogControlProps['open']>((i = 0) => {
|
const open = React.useCallback<DialogControlProps<Params>['open']>(
|
||||||
sheet.current?.snapToIndex(i)
|
(params, {snapIndex} = {}) => {
|
||||||
}, [])
|
if (params) {
|
||||||
|
console.log({params})
|
||||||
|
setParams(params)
|
||||||
|
}
|
||||||
|
sheet.current?.snapToIndex(snapIndex || 0)
|
||||||
|
},
|
||||||
|
[setParams],
|
||||||
|
)
|
||||||
|
|
||||||
const close = React.useCallback(() => {
|
const close = React.useCallback(() => {
|
||||||
sheet.current?.close()
|
sheet.current?.close()
|
||||||
@@ -53,7 +62,7 @@ export function Outer({
|
|||||||
[open, close],
|
[open, close],
|
||||||
)
|
)
|
||||||
|
|
||||||
const context = React.useMemo(() => ({close}), [close])
|
const context = React.useMemo(() => ({close, params}), [close, params])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Portal>
|
<Portal>
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ import {useLingui} from '@lingui/react'
|
|||||||
import {useTheme, atoms as a, useBreakpoints, web} from '#/alf'
|
import {useTheme, atoms as a, useBreakpoints, web} from '#/alf'
|
||||||
import {Portal} from '#/components/Portal'
|
import {Portal} from '#/components/Portal'
|
||||||
|
|
||||||
import {DialogOuterProps, DialogInnerProps} from '#/components/Dialog/types'
|
import {
|
||||||
|
DialogOuterProps,
|
||||||
|
DialogInnerProps,
|
||||||
|
DialogControlProps,
|
||||||
|
DialogParams,
|
||||||
|
} from '#/components/Dialog/types'
|
||||||
import {Context} from '#/components/Dialog/context'
|
import {Context} from '#/components/Dialog/context'
|
||||||
|
|
||||||
export {useDialogControl, useDialogContext} from '#/components/Dialog/context'
|
export {useDialogControl, useDialogContext} from '#/components/Dialog/context'
|
||||||
@@ -17,20 +22,27 @@ export {Input} from '#/components/forms/TextField'
|
|||||||
|
|
||||||
const stopPropagation = (e: any) => e.stopPropagation()
|
const stopPropagation = (e: any) => e.stopPropagation()
|
||||||
|
|
||||||
export function Outer({
|
export function Outer<Params extends DialogParams>({
|
||||||
control,
|
control,
|
||||||
onClose,
|
onClose,
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<DialogOuterProps>) {
|
}: React.PropsWithChildren<DialogOuterProps<Params>>) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
const [isOpen, setIsOpen] = React.useState(false)
|
const [isOpen, setIsOpen] = React.useState(false)
|
||||||
const [isVisible, setIsVisible] = React.useState(true)
|
const [isVisible, setIsVisible] = React.useState(true)
|
||||||
|
const [params, setParams] = React.useState({})
|
||||||
|
|
||||||
const open = React.useCallback(() => {
|
const open = React.useCallback<DialogControlProps<Params>['open']>(
|
||||||
setIsOpen(true)
|
params => {
|
||||||
}, [setIsOpen])
|
if (params) {
|
||||||
|
setParams(params)
|
||||||
|
}
|
||||||
|
setIsOpen(true)
|
||||||
|
},
|
||||||
|
[setIsOpen, setParams],
|
||||||
|
)
|
||||||
|
|
||||||
const close = React.useCallback(async () => {
|
const close = React.useCallback(async () => {
|
||||||
setIsVisible(false)
|
setIsVisible(false)
|
||||||
@@ -63,9 +75,10 @@ export function Outer({
|
|||||||
|
|
||||||
const context = React.useMemo(
|
const context = React.useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
params,
|
||||||
close,
|
close,
|
||||||
}),
|
}),
|
||||||
[close],
|
[close, params],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -4,21 +4,24 @@ import {BottomSheetProps} from '@gorhom/bottom-sheet'
|
|||||||
|
|
||||||
type A11yProps = Required<AccessibilityProps>
|
type A11yProps = Required<AccessibilityProps>
|
||||||
|
|
||||||
export type DialogContextProps = {
|
export type DialogParams = Record<string, any>
|
||||||
|
|
||||||
|
export type DialogContextProps<Params extends DialogParams> = {
|
||||||
|
params: Params
|
||||||
close: () => void
|
close: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DialogControlProps = {
|
export type DialogControlProps<Params extends DialogParams> = {
|
||||||
open: (index?: number) => void
|
open: (params?: Params, options?: {snapIndex?: number}) => void
|
||||||
close: () => void
|
close: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DialogOuterProps = {
|
export type DialogControlWithRefProps<Params extends DialogParams> = {
|
||||||
control: {
|
ref: React.RefObject<DialogControlProps<Params>>
|
||||||
ref: React.RefObject<DialogControlProps>
|
} & DialogControlProps<Params>
|
||||||
open: (index?: number) => void
|
|
||||||
close: () => void
|
export type DialogOuterProps<Params extends DialogParams> = {
|
||||||
}
|
control: DialogControlWithRefProps<Params>
|
||||||
onClose?: () => void
|
onClose?: () => void
|
||||||
nativeOptions?: {
|
nativeOptions?: {
|
||||||
sheet?: Omit<BottomSheetProps, 'children'>
|
sheet?: Omit<BottomSheetProps, 'children'>
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import * as Dialog from '#/components/Dialog'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
import {Context} from '#/components/dialogs'
|
||||||
|
|
||||||
|
export type DialogParams =
|
||||||
|
| {
|
||||||
|
type: 'post'
|
||||||
|
uri: string
|
||||||
|
cid: string
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: 'user'
|
||||||
|
did: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useReportDialogControl() {
|
||||||
|
return React.useContext(Context).report
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReportDialog() {
|
||||||
|
const control = useReportDialogControl()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog.Outer control={control}>
|
||||||
|
<Dialog.Handle />
|
||||||
|
|
||||||
|
<Dialog.ScrollableInner label="Report dialog">
|
||||||
|
<Inner />
|
||||||
|
</Dialog.ScrollableInner>
|
||||||
|
</Dialog.Outer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Inner() {
|
||||||
|
const ctx = Dialog.useDialogContext<DialogParams>()
|
||||||
|
return <Text>hello {JSON.stringify(ctx.params)}</Text>
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import * as Dialog from '#/components/Dialog'
|
||||||
|
|
||||||
|
import {DialogParams as ReportDialogParams} from '#/components/dialogs/ReportDialog'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global dialog context. Name each dialog and specify its parameters.
|
||||||
|
*/
|
||||||
|
type Context = {
|
||||||
|
report: Dialog.DialogControlWithRefProps<ReportDialogParams>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global dialog context.
|
||||||
|
*/
|
||||||
|
export const Context = React.createContext<Context>({} as Context)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global dialog context provider.
|
||||||
|
*/
|
||||||
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
const report = Dialog.useDialogControl<ReportDialogParams>()
|
||||||
|
const ctx = React.useMemo<Context>(
|
||||||
|
() => ({
|
||||||
|
report,
|
||||||
|
}),
|
||||||
|
[report],
|
||||||
|
)
|
||||||
|
|
||||||
|
return <Context.Provider value={ctx}>{children}</Context.Provider>
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {DialogControlProps} from '#/components/Dialog'
|
import {DialogControlProps} from '#/components/Dialog'
|
||||||
|
import {Provider as GlobalDialogsProvider} from '#/components/dialogs'
|
||||||
|
|
||||||
const DialogContext = React.createContext<{
|
const DialogContext = React.createContext<{
|
||||||
activeDialogs: React.MutableRefObject<
|
activeDialogs: React.MutableRefObject<
|
||||||
@@ -27,7 +28,7 @@ export function useDialogStateControlContext() {
|
|||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
const activeDialogs = React.useRef<
|
const activeDialogs = React.useRef<
|
||||||
Map<string, React.MutableRefObject<DialogControlProps>>
|
Map<string, React.MutableRefObject<DialogControlProps<{}>>>
|
||||||
>(new Map())
|
>(new Map())
|
||||||
const closeAllDialogs = React.useCallback(() => {
|
const closeAllDialogs = React.useCallback(() => {
|
||||||
activeDialogs.current.forEach(dialog => dialog.current.close())
|
activeDialogs.current.forEach(dialog => dialog.current.close())
|
||||||
@@ -37,7 +38,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
return (
|
return (
|
||||||
<DialogContext.Provider value={context}>
|
<DialogContext.Provider value={context}>
|
||||||
<DialogControlContext.Provider value={controls}>
|
<DialogControlContext.Provider value={controls}>
|
||||||
{children}
|
<GlobalDialogsProvider>{children}</GlobalDialogsProvider>
|
||||||
</DialogControlContext.Provider>
|
</DialogControlContext.Provider>
|
||||||
</DialogContext.Provider>
|
</DialogContext.Provider>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import {useLingui} from '@lingui/react'
|
|||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {isWeb} from '#/platform/detection'
|
import {isWeb} from '#/platform/detection'
|
||||||
import {richTextToString} from '#/lib/strings/rich-text-helpers'
|
import {richTextToString} from '#/lib/strings/rich-text-helpers'
|
||||||
|
import {useReportDialogControl} from '#/components/dialogs/ReportDialog'
|
||||||
|
|
||||||
let PostDropdownBtn = ({
|
let PostDropdownBtn = ({
|
||||||
testID,
|
testID,
|
||||||
@@ -63,6 +64,7 @@ let PostDropdownBtn = ({
|
|||||||
const hiddenPosts = useHiddenPosts()
|
const hiddenPosts = useHiddenPosts()
|
||||||
const {hidePost} = useHiddenPostsApi()
|
const {hidePost} = useHiddenPostsApi()
|
||||||
const openLink = useOpenLink()
|
const openLink = useOpenLink()
|
||||||
|
const reportDialogControl = useReportDialogControl()
|
||||||
|
|
||||||
const rootUri = record.reply?.root?.uri || postUri
|
const rootUri = record.reply?.root?.uri || postUri
|
||||||
const isThreadMuted = mutedThreads.includes(rootUri)
|
const isThreadMuted = mutedThreads.includes(rootUri)
|
||||||
@@ -209,11 +211,12 @@ let PostDropdownBtn = ({
|
|||||||
hasSession && {
|
hasSession && {
|
||||||
label: _(msg`Report post`),
|
label: _(msg`Report post`),
|
||||||
onPress() {
|
onPress() {
|
||||||
openModal({
|
reportDialogControl.open({type: 'post', uri: postUri, cid: postCid})
|
||||||
name: 'report',
|
// openModal({
|
||||||
uri: postUri,
|
// name: 'report',
|
||||||
cid: postCid,
|
// uri: postUri,
|
||||||
})
|
// cid: postCid,
|
||||||
|
// })
|
||||||
},
|
},
|
||||||
testID: 'postDropdownReportBtn',
|
testID: 'postDropdownReportBtn',
|
||||||
icon: {
|
icon: {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {useSession} from '#/state/session'
|
|||||||
import {useCloseAnyActiveElement} from '#/state/util'
|
import {useCloseAnyActiveElement} from '#/state/util'
|
||||||
import * as notifications from 'lib/notifications/notifications'
|
import * as notifications from 'lib/notifications/notifications'
|
||||||
import {Outlet as PortalOutlet} from '#/components/Portal'
|
import {Outlet as PortalOutlet} from '#/components/Portal'
|
||||||
|
import {ReportDialog} from '#/components/dialogs/ReportDialog'
|
||||||
|
|
||||||
function ShellInner() {
|
function ShellInner() {
|
||||||
const isDrawerOpen = useIsDrawerOpen()
|
const isDrawerOpen = useIsDrawerOpen()
|
||||||
@@ -94,8 +95,10 @@ function ShellInner() {
|
|||||||
</View>
|
</View>
|
||||||
<Composer winHeight={winDim.height} />
|
<Composer winHeight={winDim.height} />
|
||||||
<ModalsContainer />
|
<ModalsContainer />
|
||||||
<PortalOutlet />
|
|
||||||
<Lightbox />
|
<Lightbox />
|
||||||
|
|
||||||
|
<ReportDialog />
|
||||||
|
<PortalOutlet />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {useIsDrawerOpen, useSetDrawerOpen} from '#/state/shell'
|
|||||||
import {useCloseAllActiveElements} from '#/state/util'
|
import {useCloseAllActiveElements} from '#/state/util'
|
||||||
import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock'
|
import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock'
|
||||||
import {Outlet as PortalOutlet} from '#/components/Portal'
|
import {Outlet as PortalOutlet} from '#/components/Portal'
|
||||||
|
import {ReportDialog} from '#/components/dialogs/ReportDialog'
|
||||||
|
|
||||||
function ShellInner() {
|
function ShellInner() {
|
||||||
const isDrawerOpen = useIsDrawerOpen()
|
const isDrawerOpen = useIsDrawerOpen()
|
||||||
@@ -40,8 +41,11 @@ function ShellInner() {
|
|||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
<Composer winHeight={0} />
|
<Composer winHeight={0} />
|
||||||
<ModalsContainer />
|
<ModalsContainer />
|
||||||
<PortalOutlet />
|
|
||||||
<Lightbox />
|
<Lightbox />
|
||||||
|
|
||||||
|
<ReportDialog />
|
||||||
|
<PortalOutlet />
|
||||||
|
|
||||||
{!isDesktop && isDrawerOpen && (
|
{!isDesktop && isDrawerOpen && (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => setDrawerOpen(false)}
|
onPress={() => setDrawerOpen(false)}
|
||||||
|
|||||||
Reference in New Issue
Block a user