Added instructions for .well-known method (supersedes #887) (#979)

* Added instructions for .well-known method

* Factor out SelectableBtn

* Rework the ChangeHandle modal to be a little clearer

* Fix lint

* Fix desktop layout

---------

Co-authored-by: Haider Ali Punjabi <haiderali@cyberservices.com>
Co-authored-by: Haider Ali Punjabi <haideralipunjabi@hackesta.org>
zio/stable
Paul Frazee 2023-07-05 19:56:42 -05:00 committed by GitHub
parent fe32730025
commit 3a6073abb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 170 additions and 107 deletions

View File

@ -11,11 +11,12 @@ import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {ScrollView, TextInput} from './util' import {ScrollView, TextInput} from './util'
import {Text} from '../util/text/Text' import {Text} from '../util/text/Text'
import {Button} from '../util/forms/Button' import {Button} from '../util/forms/Button'
import {SelectableBtn} from '../util/forms/SelectableBtn'
import {ErrorMessage} from '../util/error/ErrorMessage' import {ErrorMessage} from '../util/error/ErrorMessage'
import {useStores} from 'state/index' import {useStores} from 'state/index'
import {ServiceDescription} from 'state/models/session' import {ServiceDescription} from 'state/models/session'
import {s} from 'lib/styles' import {s} from 'lib/styles'
import {makeValidHandle, createFullHandle} from 'lib/strings/handles' import {createFullHandle, makeValidHandle} from 'lib/strings/handles'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {useTheme} from 'lib/ThemeContext' import {useTheme} from 'lib/ThemeContext'
import {useAnalytics} from 'lib/analytics/analytics' import {useAnalytics} from 'lib/analytics/analytics'
@ -311,7 +312,7 @@ function CustomHandleForm({
const theme = useTheme() const theme = useTheme()
const [isVerifying, setIsVerifying] = React.useState(false) const [isVerifying, setIsVerifying] = React.useState(false)
const [error, setError] = React.useState<string>('') const [error, setError] = React.useState<string>('')
const [isDNSForm, setDNSForm] = React.useState<boolean>(true)
// events // events
// = // =
const onPressCopy = React.useCallback(() => { const onPressCopy = React.useCallback(() => {
@ -332,7 +333,9 @@ function CustomHandleForm({
try { try {
setIsVerifying(true) setIsVerifying(true)
setError('') setError('')
const res = await store.agent.com.atproto.identity.resolveHandle({handle}) const res = await store.agent.com.atproto.identity.resolveHandle({
handle,
})
if (res.data.did === store.me.did) { if (res.data.did === store.me.did) {
setCanSave(true) setCanSave(true)
} else { } else {
@ -384,6 +387,28 @@ function CustomHandleForm({
/> />
</View> </View>
<View style={styles.spacer} /> <View style={styles.spacer} />
<View style={[styles.selectableBtns]}>
<SelectableBtn
selected={isDNSForm}
label="DNS Panel"
left
onSelect={() => setDNSForm(true)}
accessibilityHint="Use the DNS panel"
style={s.flex1}
/>
<SelectableBtn
selected={!isDNSForm}
label="No DNS Panel"
right
onSelect={() => setDNSForm(false)}
accessibilityHint="Use a file on your server"
style={s.flex1}
/>
</View>
<View style={styles.spacer} />
{isDNSForm ? (
<>
<Text type="md" style={[pal.text, s.pb5, s.pl5]}> <Text type="md" style={[pal.text, s.pb5, s.pl5]}>
Add the following record to your domain: Add the following record to your domain:
</Text> </Text>
@ -393,7 +418,7 @@ function CustomHandleForm({
</Text> </Text>
<View style={[styles.dnsValue]}> <View style={[styles.dnsValue]}>
<Text type="mono" style={[styles.monoText, pal.text]}> <Text type="mono" style={[styles.monoText, pal.text]}>
_atproto.{handle} _atproto.
</Text> </Text>
</View> </View>
<Text type="md-medium" style={[styles.dnsLabel, pal.text]}> <Text type="md-medium" style={[styles.dnsLabel, pal.text]}>
@ -413,10 +438,37 @@ function CustomHandleForm({
</Text> </Text>
</View> </View>
</View> </View>
</>
) : (
<>
<Text type="md" style={[pal.text, s.pb5, s.pl5]}>
Upload a text file to:
</Text>
<View style={[styles.valueContainer, pal.btn]}>
<View style={[styles.dnsValue]}>
<Text type="mono" style={[styles.monoText, pal.text]}>
https://{handle}/.well-known/atproto-did
</Text>
</View>
</View>
<View style={styles.spacer} />
<Text type="md" style={[pal.text, s.pb5, s.pl5]}>
That contains the following:
</Text>
<View style={[styles.valueContainer, pal.btn]}>
<View style={[styles.dnsValue]}>
<Text type="mono" style={[styles.monoText, pal.text]}>
{store.me.did}
</Text>
</View>
</View>
</>
)}
<View style={styles.spacer} /> <View style={styles.spacer} />
<Button type="default" style={[s.p20, s.mb10]} onPress={onPressCopy}> <Button type="default" style={[s.p20, s.mb10]} onPress={onPressCopy}>
<Text type="xl" style={[pal.link, s.textCenter]}> <Text type="xl" style={[pal.link, s.textCenter]}>
Copy Domain Value Copy {isDNSForm ? 'Domain Value' : 'File Contents'}
</Text> </Text>
</Button> </Button>
{canSave === true && ( {canSave === true && (
@ -472,6 +524,10 @@ const styles = StyleSheet.create({
opacity: 0.7, opacity: 0.7,
}, },
selectableBtns: {
flexDirection: 'row',
},
title: { title: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@ -513,6 +569,11 @@ const styles = StyleSheet.create({
borderRadius: 10, borderRadius: 10,
}, },
valueContainer: {
borderRadius: 4,
paddingVertical: 16,
},
dnsTable: { dnsTable: {
borderRadius: 4, borderRadius: 4,
paddingTop: 2, paddingTop: 2,

View File

@ -0,0 +1,67 @@
import React from 'react'
import {Pressable, ViewStyle, StyleProp, StyleSheet} from 'react-native'
import {Text} from '../text/Text'
import {usePalette} from 'lib/hooks/usePalette'
import {isDesktopWeb} from 'platform/detection'
interface SelectableBtnProps {
selected: boolean
label: string
left?: boolean
right?: boolean
onSelect: () => void
accessibilityHint?: string
style?: StyleProp<ViewStyle>
}
export function SelectableBtn({
selected,
label,
left,
right,
onSelect,
accessibilityHint,
style,
}: SelectableBtnProps) {
const pal = usePalette('default')
const palPrimary = usePalette('inverted')
return (
<Pressable
style={[
styles.selectableBtn,
left && styles.selectableBtnLeft,
right && styles.selectableBtnRight,
pal.border,
selected ? palPrimary.view : pal.view,
style,
]}
onPress={onSelect}
accessibilityRole="button"
accessibilityLabel={label}
accessibilityHint={accessibilityHint}>
<Text style={selected ? palPrimary.text : pal.text}>{label}</Text>
</Pressable>
)
}
const styles = StyleSheet.create({
selectableBtn: {
flex: isDesktopWeb ? undefined : 1,
width: isDesktopWeb ? 100 : undefined,
flexDirection: 'row',
justifyContent: 'center',
borderWidth: 1,
borderLeftWidth: 0,
paddingHorizontal: 10,
paddingVertical: 10,
},
selectableBtnLeft: {
borderTopLeftRadius: 8,
borderBottomLeftRadius: 8,
borderLeftWidth: 1,
},
selectableBtnRight: {
borderTopRightRadius: 8,
borderBottomRightRadius: 8,
},
})

View File

@ -2,7 +2,6 @@ import React from 'react'
import { import {
ActivityIndicator, ActivityIndicator,
Platform, Platform,
Pressable,
StyleSheet, StyleSheet,
TextStyle, TextStyle,
TouchableOpacity, TouchableOpacity,
@ -32,6 +31,7 @@ import * as Toast from '../com/util/Toast'
import {UserAvatar} from '../com/util/UserAvatar' import {UserAvatar} from '../com/util/UserAvatar'
import {DropdownButton} from 'view/com/util/forms/DropdownButton' import {DropdownButton} from 'view/com/util/forms/DropdownButton'
import {ToggleButton} from 'view/com/util/forms/ToggleButton' import {ToggleButton} from 'view/com/util/forms/ToggleButton'
import {SelectableBtn} from 'view/com/util/forms/SelectableBtn'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {useCustomPalette} from 'lib/hooks/useCustomPalette' import {useCustomPalette} from 'lib/hooks/useCustomPalette'
import {AccountData} from 'state/models/session' import {AccountData} from 'state/models/session'
@ -40,7 +40,6 @@ import {NavigationProp} from 'lib/routes/types'
import {isDesktopWeb} from 'platform/detection' import {isDesktopWeb} from 'platform/detection'
import {pluralize} from 'lib/strings/helpers' import {pluralize} from 'lib/strings/helpers'
import {formatCount} from 'view/com/util/numeric/format' import {formatCount} from 'view/com/util/numeric/format'
import {isColorMode} from 'state/models/ui/shell'
import Clipboard from '@react-native-clipboard/clipboard' import Clipboard from '@react-native-clipboard/clipboard'
import {reset as resetNavigation} from '../../Navigation' import {reset as resetNavigation} from '../../Navigation'
@ -352,30 +351,24 @@ export const SettingsScreen = withAuthRequired(
<View> <View>
<View style={[styles.linkCard, pal.view, styles.selectableBtns]}> <View style={[styles.linkCard, pal.view, styles.selectableBtns]}>
<SelectableBtn <SelectableBtn
current={store.shell.colorMode} selected={store.shell.colorMode === 'system'}
value="system"
label="System" label="System"
left left
onChange={(v: string) => onSelect={() => store.shell.setColorMode('system')}
store.shell.setColorMode(isColorMode(v) ? v : 'system') accessibilityHint="Set color theme to system setting"
}
/> />
<SelectableBtn <SelectableBtn
current={store.shell.colorMode} selected={store.shell.colorMode === 'light'}
value="light"
label="Light" label="Light"
onChange={(v: string) => onSelect={() => store.shell.setColorMode('light')}
store.shell.setColorMode(isColorMode(v) ? v : 'system') accessibilityHint="Set color theme to light"
}
/> />
<SelectableBtn <SelectableBtn
current={store.shell.colorMode} selected={store.shell.colorMode === 'dark'}
value="dark"
label="Dark" label="Dark"
right right
onChange={(v: string) => onSelect={() => store.shell.setColorMode('dark')}
store.shell.setColorMode(isColorMode(v) ? v : 'system') accessibilityHint="Set color theme to dark"
}
/> />
</View> </View>
</View> </View>
@ -574,45 +567,6 @@ function AccountDropdownBtn({handle}: {handle: string}) {
) )
} }
interface SelectableBtnProps {
current: string
value: string
label: string
left?: boolean
right?: boolean
onChange: (v: string) => void
}
function SelectableBtn({
current,
value,
label,
left,
right,
onChange,
}: SelectableBtnProps) {
const pal = usePalette('default')
const palPrimary = usePalette('inverted')
return (
<Pressable
style={[
styles.selectableBtn,
left && styles.selectableBtnLeft,
right && styles.selectableBtnRight,
pal.border,
current === value ? palPrimary.view : pal.view,
]}
onPress={() => onChange(value)}
accessibilityRole="button"
accessibilityLabel={value}
accessibilityHint={`Set color theme to ${value}`}>
<Text style={current === value ? palPrimary.text : pal.text}>
{label}
</Text>
</Pressable>
)
}
const styles = StyleSheet.create({ const styles = StyleSheet.create({
dimmed: { dimmed: {
opacity: 0.5, opacity: 0.5,
@ -678,25 +632,6 @@ const styles = StyleSheet.create({
selectableBtns: { selectableBtns: {
flexDirection: 'row', flexDirection: 'row',
}, },
selectableBtn: {
flex: isDesktopWeb ? undefined : 1,
width: isDesktopWeb ? 100 : undefined,
flexDirection: 'row',
justifyContent: 'center',
borderWidth: 1,
borderLeftWidth: 0,
paddingHorizontal: 10,
paddingVertical: 10,
},
selectableBtnLeft: {
borderTopLeftRadius: 8,
borderBottomLeftRadius: 8,
borderLeftWidth: 1,
},
selectableBtnRight: {
borderTopRightRadius: 8,
borderBottomRightRadius: 8,
},
btn: { btn: {
flexDirection: 'row', flexDirection: 'row',