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