diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-09-05 19:36:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 11:36:19 -0700 |
commit | 117926357d3a59db8fb12f9486f657c7b0f1cf69 (patch) | |
tree | 72bc4622f02cf06d935d7ec0105de34d1c5ac84e /src | |
parent | 91c3dbd812c45cd6d58efbf58b4799c0c459b375 (diff) | |
download | voidsky-117926357d3a59db8fb12f9486f657c7b0f1cf69.tar.zst |
[Video] require email to post videos (#5152)
Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Prompt.tsx | 7 | ||||
-rw-r--r-- | src/view/com/composer/videos/SelectVideoBtn.tsx | 82 |
2 files changed, 68 insertions, 21 deletions
diff --git a/src/components/Prompt.tsx b/src/components/Prompt.tsx index 315ad0dfd..86cb5c315 100644 --- a/src/components/Prompt.tsx +++ b/src/components/Prompt.tsx @@ -8,7 +8,10 @@ import {Button, ButtonColor, ButtonProps, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {Text} from '#/components/Typography' -export {useDialogControl as usePromptControl} from '#/components/Dialog' +export { + type DialogControlProps as PromptControlProps, + useDialogControl as usePromptControl, +} from '#/components/Dialog' const Context = React.createContext<{ titleId: string @@ -23,7 +26,7 @@ export function Outer({ control, testID, }: React.PropsWithChildren<{ - control: Dialog.DialogOuterProps['control'] + control: Dialog.DialogControlProps testID?: string }>) { const {gtMobile} = useBreakpoints() diff --git a/src/view/com/composer/videos/SelectVideoBtn.tsx b/src/view/com/composer/videos/SelectVideoBtn.tsx index d8accd062..6e294ba9c 100644 --- a/src/view/com/composer/videos/SelectVideoBtn.tsx +++ b/src/view/com/composer/videos/SelectVideoBtn.tsx @@ -1,4 +1,5 @@ import React, {useCallback} from 'react' +import {Keyboard} from 'react-native' import { ImagePickerAsset, launchImageLibraryAsync, @@ -10,11 +11,14 @@ import {useLingui} from '@lingui/react' import {useVideoLibraryPermission} from '#/lib/hooks/usePermissions' import {isNative} from '#/platform/detection' +import {useModalControls} from '#/state/modals' +import {useSession} from '#/state/session' import {atoms as a, useTheme} from '#/alf' import {Button} from '#/components/Button' import {VideoClip_Stroke2_Corner0_Rounded as VideoClipIcon} from '#/components/icons/VideoClip' +import * as Prompt from '#/components/Prompt' -const VIDEO_MAX_DURATION = 90 +const VIDEO_MAX_DURATION = 60 type Props = { onSelectVideo: (video: ImagePickerAsset) => void @@ -26,33 +30,47 @@ export function SelectVideoBtn({onSelectVideo, disabled, setError}: Props) { const {_} = useLingui() const t = useTheme() const {requestVideoAccessIfNeeded} = useVideoLibraryPermission() + const control = Prompt.usePromptControl() + const {currentAccount} = useSession() const onPressSelectVideo = useCallback(async () => { if (isNative && !(await requestVideoAccessIfNeeded())) { return } - const response = await launchImageLibraryAsync({ - exif: false, - mediaTypes: MediaTypeOptions.Videos, - videoMaxDuration: VIDEO_MAX_DURATION, - quality: 1, - legacy: true, - preferredAssetRepresentationMode: - UIImagePickerPreferredAssetRepresentationMode.Current, - }) - if (response.assets && response.assets.length > 0) { - try { - onSelectVideo(response.assets[0]) - } catch (err) { - if (err instanceof Error) { - setError(err.message) - } else { - setError(_(msg`An error occurred while selecting the video`)) + if (!currentAccount?.emailConfirmed) { + Keyboard.dismiss() + control.open() + } else { + const response = await launchImageLibraryAsync({ + exif: false, + mediaTypes: MediaTypeOptions.Videos, + videoMaxDuration: VIDEO_MAX_DURATION, + quality: 1, + legacy: true, + preferredAssetRepresentationMode: + UIImagePickerPreferredAssetRepresentationMode.Current, + }) + if (response.assets && response.assets.length > 0) { + try { + onSelectVideo(response.assets[0]) + } catch (err) { + if (err instanceof Error) { + setError(err.message) + } else { + setError(_(msg`An error occurred while selecting the video`)) + } } } } - }, [onSelectVideo, requestVideoAccessIfNeeded, setError, _]) + }, [ + onSelectVideo, + requestVideoAccessIfNeeded, + setError, + _, + control, + currentAccount?.emailConfirmed, + ]) return ( <> @@ -71,6 +89,32 @@ export function SelectVideoBtn({onSelectVideo, disabled, setError}: Props) { style={disabled && t.atoms.text_contrast_low} /> </Button> + <VerifyEmailPrompt control={control} /> </> ) } + +function VerifyEmailPrompt({control}: {control: Prompt.PromptControlProps}) { + const {_} = useLingui() + const {openModal} = useModalControls() + + return ( + <Prompt.Basic + control={control} + title={_(msg`Verified email required`)} + description={_( + msg`To upload videos to Bluesky, you must first verify your email.`, + )} + confirmButtonCta={_(msg`Verify now`)} + confirmButtonColor="primary" + onConfirm={() => { + control.close(() => { + openModal({ + name: 'verify-email', + showReminder: false, + }) + }) + }} + /> + ) +} |