Bluesky app fork with some witchin' additions 馃挮 witchsky.app
bluesky fork client
at main 53 lines 1.5 kB view raw
1import {useCallback} from 'react' 2import {Keyboard} from 'react-native' 3 4import {useEmail} from '#/state/email-verification' 5import {useRequireAuth, useSession} from '#/state/session' 6import {useCloseAllActiveElements} from '#/state/util' 7import { 8 EmailDialogScreenID, 9 type Screen, 10 useEmailDialogControl, 11} from '#/components/dialogs/EmailDialog' 12 13export function useRequireEmailVerification() { 14 const {currentAccount} = useSession() 15 const {needsEmailVerification} = useEmail() 16 const requireAuth = useRequireAuth() 17 const emailDialogControl = useEmailDialogControl() 18 const closeAll = useCloseAllActiveElements() 19 20 return useCallback( 21 <T extends (...args: any[]) => any>( 22 cb: T, 23 config: Omit< 24 Extract<Screen, {id: EmailDialogScreenID.Verify}>, 25 'id' 26 > = {}, 27 ): ((...args: Parameters<T>) => ReturnType<T>) => { 28 return (...args: Parameters<T>): ReturnType<T> => { 29 if (!currentAccount) { 30 return requireAuth(() => cb(...args)) as ReturnType<T> 31 } 32 if (needsEmailVerification) { 33 Keyboard.dismiss() 34 closeAll() 35 emailDialogControl.open({ 36 id: EmailDialogScreenID.Verify, 37 ...config, 38 }) 39 return undefined as ReturnType<T> 40 } else { 41 return cb(...args) 42 } 43 } 44 }, 45 [ 46 needsEmailVerification, 47 currentAccount, 48 emailDialogControl, 49 closeAll, 50 requireAuth, 51 ], 52 ) 53}