import React from 'react' import {View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {BSKY_SERVICE} from '#/lib/constants' import * as persisted from '#/state/persisted' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import * as TextField from '#/components/forms/TextField' import * as ToggleButton from '#/components/forms/ToggleButton' import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe' import {InlineLinkText} from '#/components/Link' import {P, Text} from '#/components/Typography' export function ServerInputDialog({ control, onSelect, }: { control: Dialog.DialogOuterProps['control'] onSelect: (url: string) => void }) { const {_} = useLingui() const t = useTheme() const {gtMobile} = useBreakpoints() const [pdsAddressHistory, setPdsAddressHistory] = React.useState( persisted.get('pdsAddressHistory') || [], ) const [fixedOption, setFixedOption] = React.useState([BSKY_SERVICE]) const [customAddress, setCustomAddress] = React.useState('') const onClose = React.useCallback(() => { let url if (fixedOption[0] === 'custom') { url = customAddress.trim().toLowerCase() if (!url) { return } } else { url = fixedOption[0] } if (!url.startsWith('http://') && !url.startsWith('https://')) { if (url === 'localhost' || url.startsWith('localhost:')) { url = `http://${url}` } else { url = `https://${url}` } } if (fixedOption[0] === 'custom') { if (!pdsAddressHistory.includes(url)) { const newHistory = [url, ...pdsAddressHistory.slice(0, 4)] setPdsAddressHistory(newHistory) persisted.write('pdsAddressHistory', newHistory) } } onSelect(url) }, [ fixedOption, customAddress, onSelect, pdsAddressHistory, setPdsAddressHistory, ]) return ( Choose Service

Select the service that hosts your data.

{_(msg`Bluesky`)} {_(msg`Custom`)} {fixedOption[0] === 'custom' && ( Server address {pdsAddressHistory.length > 0 && ( {pdsAddressHistory.map(uri => ( ))} )} )}

Bluesky is an open network where you can choose your hosting provider. If you're a developer, you can host your own server. {' '} Learn more.

) }