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