Bluesky app fork with some witchin' additions 馃挮
at main 219 lines 6.6 kB view raw
1import {memo, useState} from 'react' 2import {View} from 'react-native' 3import {type AppBskyActorDefs, type ChatBskyConvoDefs} from '@atproto/api' 4import {msg, Trans} from '@lingui/macro' 5import {useLingui} from '@lingui/react' 6import {StackActions, useNavigation} from '@react-navigation/native' 7import type React from 'react' 8 9import {type NavigationProp} from '#/lib/routes/types' 10import {isNative} from '#/platform/detection' 11import {useProfileShadow} from '#/state/cache/profile-shadow' 12import {useLeaveConvo} from '#/state/queries/messages/leave-conversation' 13import { 14 useProfileBlockMutationQueue, 15 useProfileQuery, 16} from '#/state/queries/profile' 17import * as Toast from '#/view/com/util/Toast' 18import {atoms as a, platform, useBreakpoints, useTheme, web} from '#/alf' 19import {Button, ButtonText} from '#/components/Button' 20import * as Dialog from '#/components/Dialog' 21import * as Toggle from '#/components/forms/Toggle' 22import {Loader} from '#/components/Loader' 23import {Text} from '#/components/Typography' 24 25type ReportDialogParams = { 26 convoId: string 27 message: ChatBskyConvoDefs.MessageView 28} 29 30/** 31 * Dialog shown after a report is submitted, allowing the user to block the 32 * reporter and/or leave the conversation. 33 */ 34export const AfterReportDialog = memo(function BlockOrDeleteDialogInner({ 35 control, 36 params, 37 currentScreen, 38}: { 39 control: Dialog.DialogControlProps 40 params: ReportDialogParams 41 currentScreen: 'list' | 'conversation' 42}): React.ReactNode { 43 const {_} = useLingui() 44 return ( 45 <Dialog.Outer control={control} nativeOptions={{preventExpansion: true}}> 46 <Dialog.Handle /> 47 <Dialog.ScrollableInner 48 label={_( 49 msg`Would you like to block this user and/or delete this conversation?`, 50 )} 51 style={[web({maxWidth: 400})]}> 52 <DialogInner params={params} currentScreen={currentScreen} /> 53 <Dialog.Close /> 54 </Dialog.ScrollableInner> 55 </Dialog.Outer> 56 ) 57}) 58 59function DialogInner({ 60 params, 61 currentScreen, 62}: { 63 params: ReportDialogParams 64 currentScreen: 'list' | 'conversation' 65}) { 66 const t = useTheme() 67 const {_} = useLingui() 68 const control = Dialog.useDialogContext() 69 const { 70 data: profile, 71 isLoading, 72 isError, 73 } = useProfileQuery({ 74 did: params.message.sender.did, 75 }) 76 77 return isLoading ? ( 78 <View style={[a.w_full, a.py_5xl, a.align_center]}> 79 <Loader size="lg" /> 80 </View> 81 ) : isError || !profile ? ( 82 <View style={[a.w_full, a.gap_lg]}> 83 <View style={[a.justify_center, a.gap_sm]}> 84 <Text style={[a.text_2xl, a.font_semi_bold]}> 85 <Trans>Report submitted</Trans> 86 </Text> 87 <Text style={[a.text_md, t.atoms.text_contrast_medium]}> 88 <Trans>Our moderation team has received your report.</Trans> 89 </Text> 90 </View> 91 92 <Button 93 label={_(msg`Close`)} 94 onPress={() => control.close()} 95 size={platform({native: 'small', web: 'large'})} 96 color="secondary"> 97 <ButtonText> 98 <Trans>Close</Trans> 99 </ButtonText> 100 </Button> 101 </View> 102 ) : ( 103 <DoneStep 104 convoId={params.convoId} 105 currentScreen={currentScreen} 106 profile={profile} 107 /> 108 ) 109} 110 111function DoneStep({ 112 convoId, 113 currentScreen, 114 profile, 115}: { 116 convoId: string 117 currentScreen: 'list' | 'conversation' 118 profile: AppBskyActorDefs.ProfileViewDetailed 119}) { 120 const {_} = useLingui() 121 const navigation = useNavigation<NavigationProp>() 122 const control = Dialog.useDialogContext() 123 const {gtMobile} = useBreakpoints() 124 const t = useTheme() 125 const [actions, setActions] = useState<string[]>(['block', 'leave']) 126 const shadow = useProfileShadow(profile) 127 const [queueBlock] = useProfileBlockMutationQueue(shadow) 128 129 const {mutate: leaveConvo} = useLeaveConvo(convoId, { 130 onMutate: () => { 131 if (currentScreen === 'conversation') { 132 navigation.dispatch( 133 StackActions.replace('Messages', isNative ? {animation: 'pop'} : {}), 134 ) 135 } 136 }, 137 onError: () => { 138 Toast.show(_(msg`Could not leave chat`), 'xmark') 139 }, 140 }) 141 142 let btnText = _(msg`Done`) 143 let toastMsg: string | undefined 144 if (actions.includes('leave') && actions.includes('block')) { 145 btnText = _(msg`Block and Delete`) 146 toastMsg = _(msg({message: 'Conversation deleted', context: 'toast'})) 147 } else if (actions.includes('leave')) { 148 btnText = _(msg`Delete Conversation`) 149 toastMsg = _(msg({message: 'Conversation deleted', context: 'toast'})) 150 } else if (actions.includes('block')) { 151 btnText = _(msg`Block User`) 152 toastMsg = _(msg({message: 'User blocked', context: 'toast'})) 153 } 154 155 const onPressPrimaryAction = () => { 156 control.close(() => { 157 if (actions.includes('block')) { 158 queueBlock() 159 } 160 if (actions.includes('leave')) { 161 leaveConvo() 162 } 163 if (toastMsg) { 164 Toast.show(toastMsg, 'check') 165 } 166 }) 167 } 168 169 return ( 170 <View style={a.gap_2xl}> 171 <View style={[a.justify_center, gtMobile ? a.gap_sm : a.gap_xs]}> 172 <Text style={[a.text_2xl, a.font_semi_bold]}> 173 <Trans>Report submitted</Trans> 174 </Text> 175 <Text style={[a.text_md, t.atoms.text_contrast_medium]}> 176 <Trans>Our moderation team has received your report.</Trans> 177 </Text> 178 </View> 179 <Toggle.Group 180 label={_(msg`Block user and/or delete this conversation`)} 181 values={actions} 182 onChange={setActions}> 183 <View style={[a.gap_md]}> 184 <Toggle.Item name="block" label={_(msg`Block user`)}> 185 <Toggle.Checkbox /> 186 <Toggle.LabelText style={[a.text_md]}> 187 <Trans>Block user</Trans> 188 </Toggle.LabelText> 189 </Toggle.Item> 190 <Toggle.Item name="leave" label={_(msg`Delete conversation`)}> 191 <Toggle.Checkbox /> 192 <Toggle.LabelText style={[a.text_md]}> 193 <Trans>Delete conversation</Trans> 194 </Toggle.LabelText> 195 </Toggle.Item> 196 </View> 197 </Toggle.Group> 198 199 <View style={[a.gap_sm]}> 200 <Button 201 label={btnText} 202 onPress={onPressPrimaryAction} 203 size="large" 204 color={actions.length > 0 ? 'negative' : 'primary'}> 205 <ButtonText>{btnText}</ButtonText> 206 </Button> 207 <Button 208 label={_(msg`Close`)} 209 onPress={() => control.close()} 210 size="large" 211 color="secondary"> 212 <ButtonText> 213 <Trans>Close</Trans> 214 </ButtonText> 215 </Button> 216 </View> 217 </View> 218 ) 219}