support portals, minor refactor

This commit is contained in:
Samuel Newman
2024-10-09 07:51:11 +03:00
parent 242b400bb9
commit e1e148d42a
4 changed files with 142 additions and 125 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ export function GifSelectDialog({
onSelectGif: onSelectGifProp, onSelectGif: onSelectGifProp,
}: { }: {
controlRef: React.RefObject<{open: () => void}> controlRef: React.RefObject<{open: () => void}>
onClose: () => void onClose?: () => void
onSelectGif: (gif: Gif) => void onSelectGif: (gif: Gif) => void
}) { }) {
const control = Dialog.useDialogControl() const control = Dialog.useDialogControl()
+1 -5
View File
@@ -497,10 +497,6 @@ export const ComposePost = ({
openEmojiPicker?.(textInput.current?.getCursorPosition()) openEmojiPicker?.(textInput.current?.getCursorPosition())
}, [openEmojiPicker]) }, [openEmojiPicker])
const focusTextInput = useCallback(() => {
textInput.current?.focus()
}, [])
const onSelectGif = useCallback((gif: Gif) => { const onSelectGif = useCallback((gif: Gif) => {
dispatch({type: 'embed_add_gif', gif}) dispatch({type: 'embed_add_gif', gif})
}, []) }, [])
@@ -569,6 +565,7 @@ export const ComposePost = ({
dispatch({type: 'update_labels', labels: nextLabels}) dispatch({type: 'update_labels', labels: nextLabels})
}} }}
hasMedia={hasMedia || Boolean(extLink)} hasMedia={hasMedia || Boolean(extLink)}
Portal={Portal.Portal}
/> />
{canPost ? ( {canPost ? (
<Button <Button
@@ -807,7 +804,6 @@ export const ComposePost = ({
onAdd={onImageAdd} onAdd={onImageAdd}
/> />
<SelectGifBtn <SelectGifBtn
onClose={focusTextInput}
onSelectGif={onSelectGif} onSelectGif={onSelectGif}
disabled={hasMedia} disabled={hasMedia}
/> />
+44 -23
View File
@@ -4,12 +4,12 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {ShieldExclamation} from '#/lib/icons' import {ShieldExclamation} from '#/lib/icons'
import {isNative} from '#/platform/detection'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button' import {Button, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog' import * as Dialog from '#/components/Dialog'
import * as ToggleButton from '#/components/forms/ToggleButton' import * as ToggleButton from '#/components/forms/ToggleButton'
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
import {PortalComponent} from '#/components/Portal'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn'] const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn']
@@ -18,10 +18,12 @@ export function LabelsBtn({
labels, labels,
hasMedia, hasMedia,
onChange, onChange,
Portal,
}: { }: {
labels: string[] labels: string[]
hasMedia: boolean hasMedia: boolean
onChange: (v: string[]) => void onChange: (v: string[]) => void
Portal: PortalComponent
}) { }) {
const control = Dialog.useDialogControl() const control = Dialog.useDialogControl()
const t = useTheme() const t = useTheme()
@@ -52,9 +54,7 @@ export function LabelsBtn({
msg`Opens a dialog to add a content warning to your post`, msg`Opens a dialog to add a content warning to your post`,
)} )}
onPress={() => { onPress={() => {
if (isNative && Keyboard.isVisible()) {
Keyboard.dismiss() Keyboard.dismiss()
}
control.open() control.open()
}}> }}>
<ShieldExclamation style={{color: t.palette.primary_500}} size={24} /> <ShieldExclamation style={{color: t.palette.primary_500}} size={24} />
@@ -63,8 +63,41 @@ export function LabelsBtn({
) : null} ) : null}
</Button> </Button>
<Dialog.Outer control={control}> <Dialog.Outer
control={control}
Portal={Portal}
nativeOptions={{preventExpansion: true}}>
<Dialog.Handle /> <Dialog.Handle />
<DialogInner
labels={labels}
onChange={onChange}
hasAdultSelection={hasAdultSelection}
hasMedia={hasMedia}
removeAdultLabel={removeAdultLabel}
/>
</Dialog.Outer>
</>
)
}
function DialogInner({
labels,
onChange,
hasAdultSelection,
hasMedia,
removeAdultLabel,
}: {
labels: string[]
onChange: (v: string[]) => void
hasAdultSelection: boolean
hasMedia: boolean
removeAdultLabel: () => void
}) {
const {_} = useLingui()
const control = Dialog.useDialogContext()
const t = useTheme()
return (
<Dialog.ScrollableInner <Dialog.ScrollableInner
label={_(msg`Add a content warning`)} label={_(msg`Add a content warning`)}
style={[{maxWidth: 500}, a.w_full]}> style={[{maxWidth: 500}, a.w_full]}>
@@ -81,12 +114,7 @@ export function LabelsBtn({
a.rounded_md, a.rounded_md,
]}> ]}>
<View <View
style={[ style={[a.flex_row, a.align_center, a.justify_between, a.pb_sm]}>
a.flex_row,
a.align_center,
a.justify_between,
a.pb_sm,
]}>
<Text style={[a.font_bold, a.text_lg]}> <Text style={[a.font_bold, a.text_lg]}>
<Trans>Adult Content</Trans> <Trans>Adult Content</Trans>
</Text> </Text>
@@ -95,7 +123,7 @@ export function LabelsBtn({
label={_(msg`Remove`)} label={_(msg`Remove`)}
variant="ghost" variant="ghost"
color="primary" color="primary"
size="xsmall" size="tiny"
onPress={removeAdultLabel} onPress={removeAdultLabel}
disabled={!hasAdultSelection} disabled={!hasAdultSelection}
style={{opacity: hasAdultSelection ? 1 : 0}} style={{opacity: hasAdultSelection ? 1 : 0}}
@@ -116,9 +144,7 @@ export function LabelsBtn({
LayoutAnimation.Presets.easeInEaseOut, LayoutAnimation.Presets.easeInEaseOut,
) )
}}> }}>
<ToggleButton.Button <ToggleButton.Button name="sexual" label={_(msg`Suggestive`)}>
name="sexual"
label={_(msg`Suggestive`)}>
<ToggleButton.ButtonText> <ToggleButton.ButtonText>
<Trans>Suggestive</Trans> <Trans>Suggestive</Trans>
</ToggleButton.ButtonText> </ToggleButton.ButtonText>
@@ -143,9 +169,7 @@ export function LabelsBtn({
) : labels.includes('porn') ? ( ) : labels.includes('porn') ? (
<Trans>Sexual activity or erotic nudity.</Trans> <Trans>Sexual activity or erotic nudity.</Trans>
) : ( ) : (
<Trans> <Trans>If none are selected, suitable for all ages.</Trans>
If none are selected, suitable for all ages.
</Trans>
)} )}
</Text> </Text>
</> </>
@@ -156,8 +180,7 @@ export function LabelsBtn({
<Text style={[a.font_bold, t.atoms.text_contrast_medium]}> <Text style={[a.font_bold, t.atoms.text_contrast_medium]}>
Not Applicable. Not Applicable.
</Text>{' '} </Text>{' '}
This warning is only available for posts with media This warning is only available for posts with media attached.
attached.
</Trans> </Trans>
</Text> </Text>
</View> </View>
@@ -168,9 +191,9 @@ export function LabelsBtn({
<Button <Button
label={_(msg`Done`)} label={_(msg`Done`)}
onPress={() => control.close()} onPress={() => control.close()}
onAccessibilityEscape={control.close} onAccessibilityEscape={() => control.close()}
color="primary" color="primary"
size="medium" size="large"
variant="solid" variant="solid"
style={a.mt_xl}> style={a.mt_xl}>
<ButtonText> <ButtonText>
@@ -178,7 +201,5 @@ export function LabelsBtn({
</ButtonText> </ButtonText>
</Button> </Button>
</Dialog.ScrollableInner> </Dialog.ScrollableInner>
</Dialog.Outer>
</>
) )
} }
@@ -11,7 +11,7 @@ import {GifSelectDialog} from '#/components/dialogs/GifSelect'
import {GifSquare_Stroke2_Corner0_Rounded as GifIcon} from '#/components/icons/Gif' import {GifSquare_Stroke2_Corner0_Rounded as GifIcon} from '#/components/icons/Gif'
type Props = { type Props = {
onClose: () => void onClose?: () => void
onSelectGif: (gif: Gif) => void onSelectGif: (gif: Gif) => void
disabled?: boolean disabled?: boolean
} }