forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {TouchableWithoutFeedback, View} from 'react-native'
2import * as Clipboard from 'expo-clipboard'
3
4import {atoms as a, useTheme} from '#/alf'
5import * as Prompt from '#/components/Prompt'
6import * as Toast from '#/components/Toast'
7import {Text} from '#/components/Typography'
8import {useDevMode} from '#/storage/hooks/dev-mode'
9
10/**
11 * Internal-use component to display debug information supplied by the appview.
12 * The `debug` field only exists on some API views, and is only visible for
13 * internal users in dev mode. As such, none of these strings need to be
14 * translated.
15 *
16 * This component can be removed at any time if we don't find it useful.
17 */
18export function DebugFieldDisplay<T extends {debug?: {[x: string]: unknown}}>({
19 subject,
20}: {
21 subject: T
22}) {
23 const t = useTheme()
24 const [devMode] = useDevMode()
25 const prompt = Prompt.usePromptControl()
26
27 if (!devMode) return
28 if (!subject.debug) return
29
30 return (
31 <>
32 <Prompt.Basic
33 control={prompt}
34 title="Debug"
35 description={JSON.stringify(subject.debug, null, 2)}
36 cancelButtonCta="Close"
37 confirmButtonCta="Copy"
38 onConfirm={() => {
39 Clipboard.setStringAsync(JSON.stringify(subject.debug, null, 2))
40 Toast.show('Copied to clipboard', {type: 'success'})
41 }}
42 />
43 <TouchableWithoutFeedback
44 accessibilityRole="button"
45 onPress={e => {
46 e.preventDefault()
47 e.stopPropagation()
48 prompt.open()
49 return false
50 }}>
51 <View style={[a.flex_row, a.align_center, a.gap_xs, a.pt_sm, a.pb_xs]}>
52 <View
53 style={[a.py_xs, a.px_sm, a.rounded_sm, t.atoms.bg_contrast_25]}>
54 <Text
55 style={[a.font_bold, a.text_xs, t.atoms.text_contrast_medium]}>
56 Debug
57 </Text>
58 </View>
59 <Text
60 numberOfLines={1}
61 style={[
62 a.flex_1,
63 a.text_xs,
64 a.leading_tight,
65 {fontFamily: 'monospace'},
66 t.atoms.text_contrast_low,
67 ]}>
68 {JSON.stringify(subject.debug)}
69 </Text>
70 </View>
71 </TouchableWithoutFeedback>
72 </>
73 )
74}