mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
3import {ProfileModeration} from '@atproto/api'
4import {Text} from '../text/Text'
5import {usePalette} from 'lib/hooks/usePalette'
6import {ShieldExclamation} from 'lib/icons'
7import {
8 describeModerationCause,
9 getProfileModerationCauses,
10} from 'lib/moderation'
11import {msg, Trans} from '@lingui/macro'
12import {useLingui} from '@lingui/react'
13import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
14import {useModalControls} from '#/state/modals'
15
16export function ProfileHeaderAlerts({
17 moderation,
18 style,
19}: {
20 moderation: ProfileModeration
21 style?: StyleProp<ViewStyle>
22}) {
23 const pal = usePalette('default')
24 const {_} = useLingui()
25 const {openModal} = useModalControls()
26
27 const causes = getProfileModerationCauses(moderation)
28 if (!causes.length) {
29 return null
30 }
31
32 return (
33 <View style={styles.grid}>
34 {causes.map(cause => {
35 const isMute = cause.type === 'muted'
36 const desc = describeModerationCause(cause, 'account')
37 return (
38 <Pressable
39 testID="profileHeaderAlert"
40 key={desc.name}
41 onPress={() => {
42 openModal({
43 name: 'moderation-details',
44 context: 'content',
45 moderation: {cause},
46 })
47 }}
48 accessibilityRole="button"
49 accessibilityLabel={_(msg`Learn more about this warning`)}
50 accessibilityHint=""
51 style={[styles.container, pal.viewLight, style]}>
52 {isMute ? (
53 <FontAwesomeIcon
54 icon={['far', 'eye-slash']}
55 size={14}
56 color={pal.colors.textLight}
57 />
58 ) : (
59 <ShieldExclamation style={pal.text} size={18} />
60 )}
61 <Text type="sm" style={[{flex: 1}, pal.text]}>
62 {desc.name}
63 </Text>
64 <Text type="sm" style={[pal.link, styles.learnMoreBtn]}>
65 <Trans>Learn More</Trans>
66 </Text>
67 </Pressable>
68 )
69 })}
70 </View>
71 )
72}
73
74const styles = StyleSheet.create({
75 grid: {
76 gap: 4,
77 },
78 container: {
79 flexDirection: 'row',
80 alignItems: 'center',
81 gap: 8,
82 paddingVertical: 12,
83 paddingHorizontal: 16,
84 borderRadius: 8,
85 },
86 learnMoreBtn: {
87 marginLeft: 'auto',
88 },
89})