mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Pressable, View} from 'react-native'
3import {msg, Trans} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {ReportOption} from '#/lib/moderation/useReportOptions'
7import {useMyLabelersQuery} from '#/state/queries/preferences'
8export {useDialogControl as useReportDialogControl} from '#/components/Dialog'
9
10import {AppBskyLabelerDefs} from '@atproto/api'
11import {BottomSheetScrollViewMethods} from '@discord/bottom-sheet/src'
12
13import {atoms as a} from '#/alf'
14import * as Dialog from '#/components/Dialog'
15import {useDelayedLoading} from '#/components/hooks/useDelayedLoading'
16import {useOnKeyboardDidShow} from '#/components/hooks/useOnKeyboard'
17import {Loader} from '#/components/Loader'
18import {Text} from '#/components/Typography'
19import {SelectLabelerView} from './SelectLabelerView'
20import {SelectReportOptionView} from './SelectReportOptionView'
21import {SubmitView} from './SubmitView'
22import {ReportDialogProps} from './types'
23
24export function ReportDialog(props: ReportDialogProps) {
25 return (
26 <Dialog.Outer control={props.control}>
27 <Dialog.Handle />
28
29 <ReportDialogInner {...props} />
30 </Dialog.Outer>
31 )
32}
33
34function ReportDialogInner(props: ReportDialogProps) {
35 const {_} = useLingui()
36 const {
37 isLoading: isLabelerLoading,
38 data: labelers,
39 error,
40 } = useMyLabelersQuery()
41 const isLoading = useDelayedLoading(500, isLabelerLoading)
42
43 const ref = React.useRef<BottomSheetScrollViewMethods>(null)
44 useOnKeyboardDidShow(() => {
45 ref.current?.scrollToEnd({animated: true})
46 })
47
48 return (
49 <Dialog.ScrollableInner label={_(msg`Report dialog`)} ref={ref}>
50 {isLoading ? (
51 <View style={[a.align_center, {height: 100}]}>
52 <Loader size="xl" />
53 {/* Here to capture focus for a hot sec to prevent flash */}
54 <Pressable accessible={false} />
55 </View>
56 ) : error || !labelers ? (
57 <View>
58 <Text style={[a.text_md]}>
59 <Trans>Something went wrong, please try again.</Trans>
60 </Text>
61 </View>
62 ) : (
63 <ReportDialogLoaded labelers={labelers} {...props} />
64 )}
65 </Dialog.ScrollableInner>
66 )
67}
68
69function ReportDialogLoaded(
70 props: ReportDialogProps & {
71 labelers: AppBskyLabelerDefs.LabelerViewDetailed[]
72 },
73) {
74 const [selectedLabeler, setSelectedLabeler] = React.useState<
75 string | undefined
76 >(props.labelers.length === 1 ? props.labelers[0].creator.did : undefined)
77 const [selectedReportOption, setSelectedReportOption] = React.useState<
78 ReportOption | undefined
79 >()
80
81 if (selectedReportOption && selectedLabeler) {
82 return (
83 <SubmitView
84 {...props}
85 selectedLabeler={selectedLabeler}
86 selectedReportOption={selectedReportOption}
87 goBack={() => setSelectedReportOption(undefined)}
88 onSubmitComplete={() => props.control.close()}
89 />
90 )
91 }
92 if (selectedLabeler) {
93 return (
94 <SelectReportOptionView
95 {...props}
96 goBack={() => setSelectedLabeler(undefined)}
97 onSelectReportOption={setSelectedReportOption}
98 />
99 )
100 }
101 return <SelectLabelerView {...props} onSelectLabeler={setSelectedLabeler} />
102}