Fix slow Hosting Provider dialog (#7594)
* avoid portal perf pitfall * add dep array
This commit is contained in:
@@ -71,10 +71,10 @@ export function HostingProvider({
|
|||||||
a.flex_row,
|
a.flex_row,
|
||||||
a.align_center,
|
a.align_center,
|
||||||
a.rounded_sm,
|
a.rounded_sm,
|
||||||
a.px_md,
|
a.pl_md,
|
||||||
a.pr_sm,
|
a.pr_sm,
|
||||||
a.gap_xs,
|
a.gap_xs,
|
||||||
{paddingVertical: isAndroid ? 14 : 9},
|
{paddingVertical: isAndroid ? 14 : 8},
|
||||||
]}
|
]}
|
||||||
onPress={onPressSelectService}>
|
onPress={onPressSelectService}>
|
||||||
{({hovered, pressed}) => {
|
{({hovered, pressed}) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import {useCallback, useImperativeHandle, useRef, useState} from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {useWindowDimensions} from 'react-native'
|
import {useWindowDimensions} from 'react-native'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
@@ -24,28 +24,74 @@ export function ServerInputDialog({
|
|||||||
control: Dialog.DialogOuterProps['control']
|
control: Dialog.DialogOuterProps['control']
|
||||||
onSelect: (url: string) => void
|
onSelect: (url: string) => void
|
||||||
}) {
|
}) {
|
||||||
|
const {height} = useWindowDimensions()
|
||||||
|
const formRef = useRef<DialogInnerRef>(null)
|
||||||
|
|
||||||
|
// persist these options between dialog open/close
|
||||||
|
const [fixedOption, setFixedOption] = useState(BSKY_SERVICE)
|
||||||
|
const [previousCustomAddress, setPreviousCustomAddress] = useState('')
|
||||||
|
|
||||||
|
const onClose = useCallback(() => {
|
||||||
|
const result = formRef.current?.getFormState()
|
||||||
|
if (result) {
|
||||||
|
onSelect(result)
|
||||||
|
if (result !== BSKY_SERVICE) {
|
||||||
|
setPreviousCustomAddress(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [onSelect])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog.Outer
|
||||||
|
control={control}
|
||||||
|
onClose={onClose}
|
||||||
|
nativeOptions={{minHeight: height / 2}}>
|
||||||
|
<Dialog.Handle />
|
||||||
|
<DialogInner
|
||||||
|
formRef={formRef}
|
||||||
|
fixedOption={fixedOption}
|
||||||
|
setFixedOption={setFixedOption}
|
||||||
|
initialCustomAddress={previousCustomAddress}
|
||||||
|
/>
|
||||||
|
</Dialog.Outer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DialogInnerRef = {getFormState: () => string | null}
|
||||||
|
|
||||||
|
function DialogInner({
|
||||||
|
formRef,
|
||||||
|
fixedOption,
|
||||||
|
setFixedOption,
|
||||||
|
initialCustomAddress,
|
||||||
|
}: {
|
||||||
|
formRef: React.Ref<DialogInnerRef>
|
||||||
|
fixedOption: string
|
||||||
|
setFixedOption: (opt: string) => void
|
||||||
|
initialCustomAddress: string
|
||||||
|
}) {
|
||||||
|
const control = Dialog.useDialogContext()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {height} = useWindowDimensions()
|
const {accounts} = useSession()
|
||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
const [pdsAddressHistory, setPdsAddressHistory] = React.useState<string[]>(
|
const [customAddress, setCustomAddress] = useState(initialCustomAddress)
|
||||||
|
const [pdsAddressHistory, setPdsAddressHistory] = useState<string[]>(
|
||||||
persisted.get('pdsAddressHistory') || [],
|
persisted.get('pdsAddressHistory') || [],
|
||||||
)
|
)
|
||||||
const [fixedOption, setFixedOption] = React.useState([BSKY_SERVICE])
|
|
||||||
const [customAddress, setCustomAddress] = React.useState('')
|
|
||||||
const {accounts} = useSession()
|
|
||||||
|
|
||||||
const isFirstTimeUser = accounts.length === 0
|
useImperativeHandle(
|
||||||
|
formRef,
|
||||||
const onClose = React.useCallback(() => {
|
() => ({
|
||||||
|
getFormState: () => {
|
||||||
let url
|
let url
|
||||||
if (fixedOption[0] === 'custom') {
|
if (fixedOption === 'custom') {
|
||||||
url = customAddress.trim().toLowerCase()
|
url = customAddress.trim().toLowerCase()
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
url = fixedOption[0]
|
url = fixedOption
|
||||||
}
|
}
|
||||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||||
if (url === 'localhost' || url.startsWith('localhost:')) {
|
if (url === 'localhost' || url.startsWith('localhost:')) {
|
||||||
@@ -55,7 +101,7 @@ export function ServerInputDialog({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fixedOption[0] === 'custom') {
|
if (fixedOption === 'custom') {
|
||||||
if (!pdsAddressHistory.includes(url)) {
|
if (!pdsAddressHistory.includes(url)) {
|
||||||
const newHistory = [url, ...pdsAddressHistory.slice(0, 4)]
|
const newHistory = [url, ...pdsAddressHistory.slice(0, 4)]
|
||||||
setPdsAddressHistory(newHistory)
|
setPdsAddressHistory(newHistory)
|
||||||
@@ -63,21 +109,15 @@ export function ServerInputDialog({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelect(url)
|
return url
|
||||||
}, [
|
},
|
||||||
fixedOption,
|
}),
|
||||||
customAddress,
|
[customAddress, fixedOption, pdsAddressHistory],
|
||||||
onSelect,
|
)
|
||||||
pdsAddressHistory,
|
|
||||||
setPdsAddressHistory,
|
const isFirstTimeUser = accounts.length === 0
|
||||||
])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Outer
|
|
||||||
control={control}
|
|
||||||
onClose={onClose}
|
|
||||||
nativeOptions={{minHeight: height / 2}}>
|
|
||||||
<Dialog.Handle />
|
|
||||||
<Dialog.ScrollableInner
|
<Dialog.ScrollableInner
|
||||||
accessibilityDescribedBy="dialog-description"
|
accessibilityDescribedBy="dialog-description"
|
||||||
accessibilityLabelledBy="dialog-title">
|
accessibilityLabelledBy="dialog-title">
|
||||||
@@ -87,34 +127,30 @@ export function ServerInputDialog({
|
|||||||
</Text>
|
</Text>
|
||||||
<ToggleButton.Group
|
<ToggleButton.Group
|
||||||
label="Preferences"
|
label="Preferences"
|
||||||
values={fixedOption}
|
values={[fixedOption]}
|
||||||
onChange={setFixedOption}>
|
onChange={values => setFixedOption(values[0])}>
|
||||||
<ToggleButton.Button name={BSKY_SERVICE} label={_(msg`Bluesky`)}>
|
<ToggleButton.Button name={BSKY_SERVICE} label={_(msg`Bluesky`)}>
|
||||||
<ToggleButton.ButtonText>
|
<ToggleButton.ButtonText>{_(msg`Bluesky`)}</ToggleButton.ButtonText>
|
||||||
{_(msg`Bluesky`)}
|
|
||||||
</ToggleButton.ButtonText>
|
|
||||||
</ToggleButton.Button>
|
</ToggleButton.Button>
|
||||||
<ToggleButton.Button
|
<ToggleButton.Button
|
||||||
testID="customSelectBtn"
|
testID="customSelectBtn"
|
||||||
name="custom"
|
name="custom"
|
||||||
label={_(msg`Custom`)}>
|
label={_(msg`Custom`)}>
|
||||||
<ToggleButton.ButtonText>
|
<ToggleButton.ButtonText>{_(msg`Custom`)}</ToggleButton.ButtonText>
|
||||||
{_(msg`Custom`)}
|
|
||||||
</ToggleButton.ButtonText>
|
|
||||||
</ToggleButton.Button>
|
</ToggleButton.Button>
|
||||||
</ToggleButton.Group>
|
</ToggleButton.Group>
|
||||||
|
|
||||||
{fixedOption[0] === BSKY_SERVICE && isFirstTimeUser && (
|
{fixedOption === BSKY_SERVICE && isFirstTimeUser && (
|
||||||
<Admonition type="tip">
|
<Admonition type="tip">
|
||||||
<Trans>
|
<Trans>
|
||||||
Bluesky is an open network where you can choose your own
|
Bluesky is an open network where you can choose your own provider.
|
||||||
provider. If you're new here, we recommend sticking with the
|
If you're new here, we recommend sticking with the default Bluesky
|
||||||
default Bluesky Social option.
|
Social option.
|
||||||
</Trans>
|
</Trans>
|
||||||
</Admonition>
|
</Admonition>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{fixedOption[0] === 'custom' && (
|
{fixedOption === 'custom' && (
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.border,
|
a.border,
|
||||||
@@ -195,6 +231,5 @@ export function ServerInputDialog({
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</Dialog.ScrollableInner>
|
</Dialog.ScrollableInner>
|
||||||
</Dialog.Outer>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user