Something went wrong. Try again.
cee sky
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { createContext, useContext, useEffect, useId, useMemo, useRef,} from 'react'import {BottomSheetSnapPoint} from '@bsky.app/bottom-sheet/src/BottomSheet.types'
import {useDialogStateContext} from '#/state/dialogs'import { type DialogContextProps, type DialogControlRefProps, type DialogOuterProps,} from '#/components/Dialog/types'import {IS_DEV} from '#/env'
export const Context = createContext<DialogContextProps>({ close: () => {}, isNativeDialog: false, availableWidth: undefined, presentationBottomOffset: 0, isNativePopover: false, nativeSnapPoint: BottomSheetSnapPoint.Hidden, disableDrag: false, preventDismiss: false, setDisableDrag: () => {}, isWithinDialog: false, isHeightConstrained: false, setContentScrollViewTag: () => {},})Context.displayName = 'DialogContext'
export function useDialogContext() { return useContext(Context)}
export function useDialogControl(): DialogOuterProps['control'] { const id = useId() const control = useRef<DialogControlRefProps>({ open: () => {}, close: () => {}, }) const {activeDialogs} = useDialogStateContext()
useEffect(() => { activeDialogs.current.set(id, control) return () => { activeDialogs.current.delete(id) } }, [id, activeDialogs])
return useMemo<DialogOuterProps['control']>( () => ({ id, ref: control, open: options => { if (control.current) { control.current.open(options) } else { if (IS_DEV) { console.warn( 'Attemped to open a dialog control that was not attached to a dialog!\n' + 'Please ensure that the Dialog is mounted when calling open/close', ) } } }, close: cb => { if (control.current) { control.current.close(cb) } else { if (IS_DEV) { console.warn( 'Attemped to close a dialog control that was not attached to a dialog!\n' + 'Please ensure that the Dialog is mounted when calling open/close', ) } } }, }), [id, control], )}