mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Keyboard, View} from 'react-native'
3import {msg} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {toNiceDomain} from '#/lib/strings/url-helpers'
7import {isAndroid} from '#/platform/detection'
8import {ServerInputDialog} from '#/view/com/auth/server-input'
9import {atoms as a, useTheme} from '#/alf'
10import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe'
11import {PencilLine_Stroke2_Corner0_Rounded as Pencil} from '#/components/icons/Pencil'
12import {Button} from '../Button'
13import {useDialogControl} from '../Dialog'
14import {Text} from '../Typography'
15
16export function HostingProvider({
17 serviceUrl,
18 onSelectServiceUrl,
19 onOpenDialog,
20}: {
21 serviceUrl: string
22 onSelectServiceUrl: (provider: string) => void
23 onOpenDialog?: () => void
24}) {
25 const serverInputControl = useDialogControl()
26 const t = useTheme()
27 const {_} = useLingui()
28
29 const onPressSelectService = React.useCallback(() => {
30 Keyboard.dismiss()
31 serverInputControl.open()
32 if (onOpenDialog) {
33 onOpenDialog()
34 }
35 }, [onOpenDialog, serverInputControl])
36
37 return (
38 <>
39 <ServerInputDialog
40 control={serverInputControl}
41 onSelect={onSelectServiceUrl}
42 />
43 <Button
44 testID="loginSelectServiceButton"
45 label={toNiceDomain(serviceUrl)}
46 accessibilityHint={_(msg`Press to change hosting provider`)}
47 variant="solid"
48 color="secondary"
49 style={[
50 a.w_full,
51 a.flex_row,
52 a.align_center,
53 a.rounded_sm,
54 a.px_md,
55 a.pr_sm,
56 a.gap_xs,
57 {paddingVertical: isAndroid ? 14 : 9},
58 ]}
59 onPress={onPressSelectService}>
60 {({hovered, pressed}) => {
61 const interacted = hovered || pressed
62 return (
63 <>
64 <View style={a.pr_xs}>
65 <Globe
66 size="md"
67 fill={
68 interacted ? t.palette.contrast_800 : t.palette.contrast_500
69 }
70 />
71 </View>
72 <Text style={[a.text_md]}>{toNiceDomain(serviceUrl)}</Text>
73 <View
74 style={[
75 a.rounded_sm,
76 interacted
77 ? t.atoms.bg_contrast_300
78 : t.atoms.bg_contrast_100,
79 {marginLeft: 'auto', padding: 6},
80 ]}>
81 <Pencil
82 size="sm"
83 style={{
84 color: interacted
85 ? t.palette.contrast_800
86 : t.palette.contrast_500,
87 }}
88 />
89 </View>
90 </>
91 )
92 }}
93 </Button>
94 </>
95 )
96}