about summary refs log tree commit diff
path: root/src/view/com/util/moderation/PostHider.tsx
blob: f2b6dbddd68e8aa0a31792c60df46761bc9efdca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, {ComponentProps} from 'react'
import {StyleSheet, TouchableOpacity, View} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {usePalette} from 'lib/hooks/usePalette'
import {Link} from '../Link'
import {Text} from '../text/Text'
import {addStyle} from 'lib/styles'
import {ModerationBehaviorCode, ModerationBehavior} from 'lib/labeling/types'

interface Props extends ComponentProps<typeof Link> {
  // testID?: string
  // href?: string
  // style: StyleProp<ViewStyle>
  moderation: ModerationBehavior
}

export function PostHider({
  testID,
  href,
  moderation,
  style,
  children,
  ...props
}: Props) {
  const pal = usePalette('default')
  const [override, setOverride] = React.useState(false)
  const bg = override ? pal.viewLight : pal.view

  if (moderation.behavior === ModerationBehaviorCode.Hide) {
    return null
  }

  if (moderation.behavior === ModerationBehaviorCode.Warn) {
    return (
      <>
        <View style={[styles.description, bg, pal.border]}>
          <FontAwesomeIcon
            icon={['far', 'eye-slash']}
            style={[styles.icon, pal.text]}
          />
          <Text type="md" style={pal.textLight}>
            {moderation.reason || 'Content warning'}
          </Text>
          <TouchableOpacity
            style={styles.showBtn}
            onPress={() => setOverride(v => !v)}
            accessibilityRole="button">
            <Text type="md" style={pal.link}>
              {override ? 'Hide' : 'Show'} post
            </Text>
          </TouchableOpacity>
        </View>
        {override && (
          <View style={[styles.childrenContainer, pal.border, bg]}>
            <Link
              testID={testID}
              style={addStyle(style, styles.child)}
              href={href}
              noFeedback>
              {children}
            </Link>
          </View>
        )}
      </>
    )
  }

  // NOTE: any further label enforcement should occur in ContentContainer
  return (
    <Link
      testID={testID}
      style={style}
      href={href}
      noFeedback
      accessible={false}
      {...props}>
      {children}
    </Link>
  )
}

const styles = StyleSheet.create({
  description: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingVertical: 14,
    paddingHorizontal: 18,
    borderTopWidth: 1,
  },
  icon: {
    marginRight: 10,
  },
  showBtn: {
    marginLeft: 'auto',
  },
  childrenContainer: {
    paddingHorizontal: 6,
    paddingBottom: 6,
  },
  child: {
    borderWidth: 1,
    borderRadius: 12,
  },
})