mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {View} from 'react-native'
3import {AppBskyActorDefs, ModerationCause} from '@atproto/api'
4import {msg, Trans} from '@lingui/macro'
5import {useLingui} from '@lingui/react'
6
7import {useProfileShadow} from 'state/cache/profile-shadow'
8import {useProfileBlockMutationQueue} from 'state/queries/profile'
9import {atoms as a, useBreakpoints, useTheme} from '#/alf'
10import {Button, ButtonText} from '#/components/Button'
11import {useDialogControl} from '#/components/Dialog'
12import {Divider} from '#/components/Divider'
13import {BlockedByListDialog} from '#/components/dms/BlockedByListDialog'
14import {LeaveConvoPrompt} from '#/components/dms/LeaveConvoPrompt'
15import {ReportConversationPrompt} from '#/components/dms/ReportConversationPrompt'
16import {Text} from '#/components/Typography'
17
18export function MessagesListBlockedFooter({
19 recipient: initialRecipient,
20 convoId,
21 hasMessages,
22 blockInfo,
23}: {
24 recipient: AppBskyActorDefs.ProfileViewBasic
25 convoId: string
26 hasMessages: boolean
27 blockInfo: {
28 listBlocks: ModerationCause[]
29 userBlock: ModerationCause | undefined
30 }
31}) {
32 const t = useTheme()
33 const {gtMobile} = useBreakpoints()
34 const {_} = useLingui()
35 const recipient = useProfileShadow(initialRecipient)
36 const [__, queueUnblock] = useProfileBlockMutationQueue(recipient)
37
38 const leaveConvoControl = useDialogControl()
39 const reportControl = useDialogControl()
40 const blockedByListControl = useDialogControl()
41
42 const {listBlocks, userBlock} = blockInfo
43 const isBlocking = !!userBlock || !!listBlocks.length
44
45 const onUnblockPress = React.useCallback(() => {
46 if (listBlocks.length) {
47 blockedByListControl.open()
48 } else {
49 queueUnblock()
50 }
51 }, [blockedByListControl, listBlocks, queueUnblock])
52
53 return (
54 <View style={[hasMessages && a.pt_md, a.pb_xl, a.gap_lg]}>
55 <Divider />
56 <Text style={[a.text_md, a.font_bold, a.text_center]}>
57 {isBlocking ? (
58 <Trans>You have blocked this user</Trans>
59 ) : (
60 <Trans>This user has blocked you</Trans>
61 )}
62 </Text>
63
64 <View style={[a.flex_row, a.justify_between, a.gap_lg, a.px_md]}>
65 <Button
66 label={_(msg`Leave chat`)}
67 color="secondary"
68 variant="solid"
69 size="small"
70 style={[a.flex_1]}
71 onPress={leaveConvoControl.open}>
72 <ButtonText style={{color: t.palette.negative_500}}>
73 <Trans>Leave chat</Trans>
74 </ButtonText>
75 </Button>
76 <Button
77 label={_(msg`Report`)}
78 color="secondary"
79 variant="solid"
80 size="small"
81 style={[a.flex_1]}
82 onPress={reportControl.open}>
83 <ButtonText style={{color: t.palette.negative_500}}>
84 <Trans>Report</Trans>
85 </ButtonText>
86 </Button>
87 {isBlocking && gtMobile && (
88 <Button
89 label={_(msg`Unblock`)}
90 color="secondary"
91 variant="solid"
92 size="small"
93 style={[a.flex_1]}
94 onPress={onUnblockPress}>
95 <ButtonText style={{color: t.palette.primary_500}}>
96 <Trans>Unblock</Trans>
97 </ButtonText>
98 </Button>
99 )}
100 </View>
101 {isBlocking && !gtMobile && (
102 <View style={[a.flex_row, a.justify_center, a.px_md]}>
103 <Button
104 label={_(msg`Unblock`)}
105 color="secondary"
106 variant="solid"
107 size="small"
108 style={[a.flex_1]}
109 onPress={onUnblockPress}>
110 <ButtonText style={{color: t.palette.primary_500}}>
111 <Trans>Unblock</Trans>
112 </ButtonText>
113 </Button>
114 </View>
115 )}
116
117 <LeaveConvoPrompt
118 control={leaveConvoControl}
119 currentScreen="conversation"
120 convoId={convoId}
121 />
122
123 <ReportConversationPrompt control={reportControl} />
124
125 <BlockedByListDialog
126 control={blockedByListControl}
127 listBlocks={listBlocks}
128 />
129 </View>
130 )
131}