about summary refs log tree commit diff
path: root/src/components/ReportDialog/index.tsx
blob: b35727c7dd9d7944f10b465b8db5dfafb04dd1e8 (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
import React from 'react'
import {View, Pressable} from 'react-native'
import {Trans} from '@lingui/macro'

import {useMyLabelersQuery} from '#/state/queries/preferences'
import {ReportOption} from '#/lib/moderation/useReportOptions'
export {useDialogControl as useReportDialogControl} from '#/components/Dialog'

import {atoms as a} from '#/alf'
import {Loader} from '#/components/Loader'
import * as Dialog from '#/components/Dialog'
import {Text} from '#/components/Typography'

import {ReportDialogProps} from './types'
import {SelectReportOptionView} from './SelectReportOptionView'
import {SubmitView} from './SubmitView'
import {useDelayedLoading} from '#/components/hooks/useDelayedLoading'

export function ReportDialog(props: ReportDialogProps) {
  return (
    <Dialog.Outer control={props.control}>
      <Dialog.Handle />

      <ReportDialogInner {...props} />
    </Dialog.Outer>
  )
}

function ReportDialogInner(props: ReportDialogProps) {
  const {
    isLoading: isLabelerLoading,
    data: labelers,
    error,
  } = useMyLabelersQuery()
  const isLoading = useDelayedLoading(500, isLabelerLoading)
  const [selectedReportOption, setSelectedReportOption] = React.useState<
    ReportOption | undefined
  >()

  return (
    <Dialog.ScrollableInner label="Report Dialog">
      {isLoading ? (
        <View style={[a.align_center, {height: 100}]}>
          <Loader size="xl" />
          {/* Here to capture focus for a hot sec to prevent flash */}
          <Pressable accessible={false} />
        </View>
      ) : error || !labelers ? (
        <View>
          <Text style={[a.text_md]}>
            <Trans>Something went wrong, please try again.</Trans>
          </Text>
        </View>
      ) : selectedReportOption ? (
        <SubmitView
          {...props}
          labelers={labelers}
          selectedReportOption={selectedReportOption}
          goBack={() => setSelectedReportOption(undefined)}
          onSubmitComplete={() => props.control.close()}
        />
      ) : (
        <SelectReportOptionView
          {...props}
          labelers={labelers}
          onSelectReportOption={setSelectedReportOption}
        />
      )}

      <Dialog.Close />
    </Dialog.ScrollableInner>
  )
}