mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at rm-proxy 75 lines 2.4 kB view raw
1import React from 'react' 2import {Keyboard, StyleProp, ViewStyle} from 'react-native' 3import Animated, {AnimatedStyle} from 'react-native-reanimated' 4import {msg} from '@lingui/macro' 5import {useLingui} from '@lingui/react' 6 7import {isNative} from '#/platform/detection' 8import {ThreadgateSetting} from '#/state/queries/threadgate' 9import {useAnalytics} from 'lib/analytics/analytics' 10import {atoms as a, useTheme} from '#/alf' 11import {Button, ButtonIcon, ButtonText} from '#/components/Button' 12import * as Dialog from '#/components/Dialog' 13import {ThreadgateEditorDialog} from '#/components/dialogs/ThreadgateEditor' 14import {CircleBanSign_Stroke2_Corner0_Rounded as CircleBanSign} from '#/components/icons/CircleBanSign' 15import {Earth_Stroke2_Corner0_Rounded as Earth} from '#/components/icons/Globe' 16import {Group3_Stroke2_Corner0_Rounded as Group} from '#/components/icons/Group' 17 18export function ThreadgateBtn({ 19 threadgate, 20 onChange, 21 style, 22}: { 23 threadgate: ThreadgateSetting[] 24 onChange: (v: ThreadgateSetting[]) => void 25 style?: StyleProp<AnimatedStyle<ViewStyle>> 26}) { 27 const {track} = useAnalytics() 28 const {_} = useLingui() 29 const t = useTheme() 30 const control = Dialog.useDialogControl() 31 32 const onPress = () => { 33 track('Composer:ThreadgateOpened') 34 if (isNative && Keyboard.isVisible()) { 35 Keyboard.dismiss() 36 } 37 38 control.open() 39 } 40 41 const isEverybody = threadgate.length === 0 42 const isNobody = !!threadgate.find(gate => gate.type === 'nobody') 43 const label = isEverybody 44 ? _(msg`Everybody can reply`) 45 : isNobody 46 ? _(msg`Nobody can reply`) 47 : _(msg`Some people can reply`) 48 49 return ( 50 <> 51 <Animated.View style={[a.flex_row, a.p_sm, t.atoms.bg, style]}> 52 <Button 53 variant="solid" 54 color="secondary" 55 size="xsmall" 56 testID="openReplyGateButton" 57 onPress={onPress} 58 label={label} 59 accessibilityHint={_( 60 msg`Opens a dialog to choose who can reply to this thread`, 61 )}> 62 <ButtonIcon 63 icon={isEverybody ? Earth : isNobody ? CircleBanSign : Group} 64 /> 65 <ButtonText>{label}</ButtonText> 66 </Button> 67 </Animated.View> 68 <ThreadgateEditorDialog 69 control={control} 70 threadgate={threadgate} 71 onChange={onChange} 72 /> 73 </> 74 ) 75}