mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at vouch-impl 84 lines 2.7 kB view raw
1import {Keyboard, StyleProp, ViewStyle} from 'react-native' 2import {AnimatedStyle} from 'react-native-reanimated' 3import {AppBskyFeedPostgate} from '@atproto/api' 4import {msg} from '@lingui/macro' 5import {useLingui} from '@lingui/react' 6 7import {isNative} from '#/platform/detection' 8import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' 9import {native} from '#/alf' 10import {Button, ButtonIcon, ButtonText} from '#/components/Button' 11import * as Dialog from '#/components/Dialog' 12import {PostInteractionSettingsControlledDialog} from '#/components/dialogs/PostInteractionSettingsDialog' 13import {Earth_Stroke2_Corner0_Rounded as Earth} from '#/components/icons/Globe' 14import {Group3_Stroke2_Corner0_Rounded as Group} from '#/components/icons/Group' 15 16export function ThreadgateBtn({ 17 postgate, 18 onChangePostgate, 19 threadgateAllowUISettings, 20 onChangeThreadgateAllowUISettings, 21}: { 22 postgate: AppBskyFeedPostgate.Record 23 onChangePostgate: (v: AppBskyFeedPostgate.Record) => void 24 25 threadgateAllowUISettings: ThreadgateAllowUISetting[] 26 onChangeThreadgateAllowUISettings: (v: ThreadgateAllowUISetting[]) => void 27 28 style?: StyleProp<AnimatedStyle<ViewStyle>> 29}) { 30 const {_} = useLingui() 31 const control = Dialog.useDialogControl() 32 33 const onPress = () => { 34 if (isNative && Keyboard.isVisible()) { 35 Keyboard.dismiss() 36 } 37 38 control.open() 39 } 40 41 const anyoneCanReply = 42 threadgateAllowUISettings.length === 1 && 43 threadgateAllowUISettings[0].type === 'everybody' 44 const anyoneCanQuote = 45 !postgate.embeddingRules || postgate.embeddingRules.length === 0 46 const anyoneCanInteract = anyoneCanReply && anyoneCanQuote 47 const label = anyoneCanInteract 48 ? _(msg`Anybody can interact`) 49 : _(msg`Interaction limited`) 50 51 return ( 52 <> 53 <Button 54 variant="solid" 55 color="secondary" 56 size="small" 57 testID="openReplyGateButton" 58 onPress={onPress} 59 label={label} 60 accessibilityHint={_( 61 msg`Opens a dialog to choose who can reply to this thread`, 62 )} 63 style={[ 64 native({ 65 paddingHorizontal: 8, 66 paddingVertical: 6, 67 }), 68 ]}> 69 <ButtonIcon icon={anyoneCanInteract ? Earth : Group} /> 70 <ButtonText numberOfLines={1}>{label}</ButtonText> 71 </Button> 72 <PostInteractionSettingsControlledDialog 73 control={control} 74 onSave={() => { 75 control.close() 76 }} 77 postgate={postgate} 78 onChangePostgate={onChangePostgate} 79 threadgateAllowUISettings={threadgateAllowUISettings} 80 onChangeThreadgateAllowUISettings={onChangeThreadgateAllowUISettings} 81 /> 82 </> 83 ) 84}