From e1e148d42a54879a948276e21824ba5ec217cfef Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 9 Oct 2024 07:51:11 +0300 Subject: [PATCH] support portals, minor refactor --- src/components/dialogs/GifSelect.tsx | 2 +- src/view/com/composer/Composer.tsx | 6 +- src/view/com/composer/labels/LabelsBtn.tsx | 257 ++++++++++-------- src/view/com/composer/photos/SelectGifBtn.tsx | 2 +- 4 files changed, 142 insertions(+), 125 deletions(-) diff --git a/src/components/dialogs/GifSelect.tsx b/src/components/dialogs/GifSelect.tsx index ffd8130db5..64ad2624a4 100644 --- a/src/components/dialogs/GifSelect.tsx +++ b/src/components/dialogs/GifSelect.tsx @@ -37,7 +37,7 @@ export function GifSelectDialog({ onSelectGif: onSelectGifProp, }: { controlRef: React.RefObject<{open: () => void}> - onClose: () => void + onClose?: () => void onSelectGif: (gif: Gif) => void }) { const control = Dialog.useDialogControl() diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 49a498ccee..75e2e9f3a2 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -497,10 +497,6 @@ export const ComposePost = ({ openEmojiPicker?.(textInput.current?.getCursorPosition()) }, [openEmojiPicker]) - const focusTextInput = useCallback(() => { - textInput.current?.focus() - }, []) - const onSelectGif = useCallback((gif: Gif) => { dispatch({type: 'embed_add_gif', gif}) }, []) @@ -569,6 +565,7 @@ export const ComposePost = ({ dispatch({type: 'update_labels', labels: nextLabels}) }} hasMedia={hasMedia || Boolean(extLink)} + Portal={Portal.Portal} /> {canPost ? ( - + - - - - Add a content warning - - - - - - Adult Content - - - - - {hasMedia ? ( - <> - { - onChange(values) - LayoutAnimation.configureNext( - LayoutAnimation.Presets.easeInEaseOut, - ) - }}> - - - Suggestive - - - - - Nudity - - - - - Porn - - - - - - {labels.includes('sexual') ? ( - Pictures meant for adults. - ) : labels.includes('nudity') ? ( - Artistic or non-erotic nudity. - ) : labels.includes('porn') ? ( - Sexual activity or erotic nudity. - ) : ( - - If none are selected, suitable for all ages. - - )} - - - ) : ( - - - - - Not Applicable. - {' '} - This warning is only available for posts with media - attached. - - - - )} - - - - - + ) } + +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 ( + + + + Add a content warning + + + + + + Adult Content + + + + + {hasMedia ? ( + <> + { + onChange(values) + LayoutAnimation.configureNext( + LayoutAnimation.Presets.easeInEaseOut, + ) + }}> + + + Suggestive + + + + + Nudity + + + + + Porn + + + + + + {labels.includes('sexual') ? ( + Pictures meant for adults. + ) : labels.includes('nudity') ? ( + Artistic or non-erotic nudity. + ) : labels.includes('porn') ? ( + Sexual activity or erotic nudity. + ) : ( + If none are selected, suitable for all ages. + )} + + + ) : ( + + + + + Not Applicable. + {' '} + This warning is only available for posts with media attached. + + + + )} + + + + + + ) +} diff --git a/src/view/com/composer/photos/SelectGifBtn.tsx b/src/view/com/composer/photos/SelectGifBtn.tsx index d13df0a110..74f9acdc63 100644 --- a/src/view/com/composer/photos/SelectGifBtn.tsx +++ b/src/view/com/composer/photos/SelectGifBtn.tsx @@ -11,7 +11,7 @@ import {GifSelectDialog} from '#/components/dialogs/GifSelect' import {GifSquare_Stroke2_Corner0_Rounded as GifIcon} from '#/components/icons/Gif' type Props = { - onClose: () => void + onClose?: () => void onSelectGif: (gif: Gif) => void disabled?: boolean }