Bluesky app fork with some witchin' additions 馃挮
at linkat-integration 126 lines 4.4 kB view raw
1import {type AppBskyGraphDefs} from '@atproto/api' 2import {msg, Trans} from '@lingui/macro' 3import {useLingui} from '@lingui/react' 4 5import {useEnableSquareButtons} from '#/state/preferences/enable-square-buttons' 6import {useListBlockMutation, useListMuteMutation} from '#/state/queries/list' 7import {atoms as a} from '#/alf' 8import {Button, ButtonIcon, ButtonText} from '#/components/Button' 9import {Mute_Stroke2_Corner0_Rounded as MuteIcon} from '#/components/icons/Mute' 10import {PersonX_Stroke2_Corner0_Rounded as PersonXIcon} from '#/components/icons/Person' 11import {Loader} from '#/components/Loader' 12import * as Menu from '#/components/Menu' 13import * as Prompt from '#/components/Prompt' 14import * as Toast from '#/components/Toast' 15import {useAnalytics} from '#/analytics' 16 17export function SubscribeMenu({list}: {list: AppBskyGraphDefs.ListView}) { 18 const {_} = useLingui() 19 const ax = useAnalytics() 20 const subscribeMutePromptControl = Prompt.usePromptControl() 21 const subscribeBlockPromptControl = Prompt.usePromptControl() 22 23 const {mutateAsync: muteList, isPending: isMutePending} = 24 useListMuteMutation() 25 const {mutateAsync: blockList, isPending: isBlockPending} = 26 useListBlockMutation() 27 28 const isPending = isMutePending || isBlockPending 29 30 const enableSquareButtons = useEnableSquareButtons() 31 32 const onSubscribeMute = async () => { 33 try { 34 await muteList({uri: list.uri, mute: true}) 35 Toast.show(_(msg({message: 'List muted', context: 'toast'}))) 36 ax.metric('moderation:subscribedToList', {listType: 'mute'}) 37 } catch { 38 Toast.show( 39 _( 40 msg`There was an issue. Please check your internet connection and try again.`, 41 ), 42 {type: 'error'}, 43 ) 44 } 45 } 46 47 const onSubscribeBlock = async () => { 48 try { 49 await blockList({uri: list.uri, block: true}) 50 Toast.show(_(msg({message: 'List blocked', context: 'toast'}))) 51 ax.metric('moderation:subscribedToList', {listType: 'block'}) 52 } catch { 53 Toast.show( 54 _( 55 msg`There was an issue. Please check your internet connection and try again.`, 56 ), 57 {type: 'error'}, 58 ) 59 } 60 } 61 62 return ( 63 <> 64 <Menu.Root> 65 <Menu.Trigger label={_(msg`Subscribe to this list`)}> 66 {({props}) => ( 67 <Button 68 label={props.accessibilityLabel} 69 testID="subscribeBtn" 70 size="small" 71 color="primary_subtle" 72 style={[enableSquareButtons ? a.rounded_sm : a.rounded_full]} 73 disabled={isPending} 74 {...props}> 75 {isPending && <ButtonIcon icon={Loader} />} 76 <ButtonText> 77 <Trans>Subscribe</Trans> 78 </ButtonText> 79 </Button> 80 )} 81 </Menu.Trigger> 82 <Menu.Outer showCancel> 83 <Menu.Group> 84 <Menu.Item 85 label={_(msg`Mute accounts`)} 86 onPress={subscribeMutePromptControl.open}> 87 <Menu.ItemText> 88 <Trans>Mute accounts</Trans> 89 </Menu.ItemText> 90 <Menu.ItemIcon position="right" icon={MuteIcon} /> 91 </Menu.Item> 92 <Menu.Item 93 label={_(msg`Block accounts`)} 94 onPress={subscribeBlockPromptControl.open}> 95 <Menu.ItemText> 96 <Trans>Block accounts</Trans> 97 </Menu.ItemText> 98 <Menu.ItemIcon position="right" icon={PersonXIcon} /> 99 </Menu.Item> 100 </Menu.Group> 101 </Menu.Outer> 102 </Menu.Root> 103 104 <Prompt.Basic 105 control={subscribeMutePromptControl} 106 title={_(msg`Mute these accounts?`)} 107 description={_( 108 msg`Muting is private. Muted accounts can interact with you, but you will not see their skeets or receive notifications from them.`, 109 )} 110 onConfirm={onSubscribeMute} 111 confirmButtonCta={_(msg`Mute list`)} 112 /> 113 114 <Prompt.Basic 115 control={subscribeBlockPromptControl} 116 title={_(msg`Block these accounts?`)} 117 description={_( 118 msg`Blocking is public. Blocked accounts cannot reply in your threads, mention you, or otherwise interact with you.`, 119 )} 120 onConfirm={onSubscribeBlock} 121 confirmButtonCta={_(msg`Block list`)} 122 confirmButtonColor="negative" 123 /> 124 </> 125 ) 126}