chore: fix server selection ux [skip e2e]

This commit is contained in:
Mo
2024-01-06 16:35:58 -06:00
parent 23efad85df
commit 04106b3e15
4 changed files with 48 additions and 28 deletions

View File

@@ -940,7 +940,7 @@ export class SyncService
return return
} }
if (options.checkIntegrity) { if (options.checkIntegrity && online) {
await this.notifyEventSync(SyncEvent.SyncRequestsIntegrityCheck, { await this.notifyEventSync(SyncEvent.SyncRequestsIntegrityCheck, {
source: options.source as SyncSource, source: options.source as SyncSource,
}) })

View File

@@ -50,12 +50,7 @@ export class DesktopManager
void this.backups.importWatchedDirectoryChanges(changes) void this.backups.importWatchedDirectoryChanges(changes)
} }
async handleHomeServerStarted(serverUrl: string): Promise<void> { async handleHomeServerStarted(_serverUrl: string): Promise<void> {}
const userIsSignedIn = this.application.sessions.isSignedIn()
if (!userIsSignedIn) {
await this.application.setCustomHost(serverUrl)
}
}
beginTextBackupsTimer() { beginTextBackupsTimer() {
if (this.textBackupsInterval) { if (this.textBackupsInterval) {

View File

@@ -5,6 +5,7 @@ import DecoratedInput from '@/Components/Input/DecoratedInput'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import { useApplication } from '../ApplicationProvider' import { useApplication } from '../ApplicationProvider'
import ServerPicker from './ServerPicker/ServerPicker' import ServerPicker from './ServerPicker/ServerPicker'
import { DefaultHost } from '@standardnotes/snjs'
type Props = { type Props = {
disabled?: boolean disabled?: boolean
@@ -23,8 +24,9 @@ const AdvancedOptions: FunctionComponent<Props> = ({
}) => { }) => {
const application = useApplication() const application = useApplication()
const { server, setServer } = application.accountMenuController const { server } = application.accountMenuController
const [showAdvanced, setShowAdvanced] = useState(false)
const [showAdvanced, setShowAdvanced] = useState(server !== DefaultHost.Api)
const [isPrivateUsername, setIsPrivateUsername] = useState(false) const [isPrivateUsername, setIsPrivateUsername] = useState(false)
const [privateUsername, setPrivateUsername] = useState('') const [privateUsername, setPrivateUsername] = useState('')
@@ -34,6 +36,14 @@ const AdvancedOptions: FunctionComponent<Props> = ({
const [isStrictSignin, setIsStrictSignin] = useState(false) const [isStrictSignin, setIsStrictSignin] = useState(false)
useEffect(() => {
void application.homeServer?.isHomeServerRunning().then((isRunning) => {
if (isRunning) {
setShowAdvanced(true)
}
})
}, [application.homeServer])
useEffect(() => { useEffect(() => {
const recomputePrivateUsername = async () => { const recomputePrivateUsername = async () => {
const identifier = await application.computePrivateUsername(privateUsername) const identifier = await application.computePrivateUsername(privateUsername)
@@ -85,14 +95,6 @@ const AdvancedOptions: FunctionComponent<Props> = ({
[onRecoveryCodesChange], [onRecoveryCodesChange],
) )
const handleSyncServerChange = useCallback(
(server: string, websocketUrl?: string) => {
setServer(server)
application.setCustomHost(server, websocketUrl).catch(console.error)
},
[application, setServer],
)
const handleStrictSigninChange = useCallback(() => { const handleStrictSigninChange = useCallback(() => {
const newValue = !isStrictSignin const newValue = !isStrictSignin
setIsStrictSignin(newValue) setIsStrictSignin(newValue)
@@ -194,7 +196,7 @@ const AdvancedOptions: FunctionComponent<Props> = ({
</> </>
)} )}
</div> </div>
<ServerPicker customServerAddress={server} handleCustomServerAddressChange={handleSyncServerChange} /> <ServerPicker />
</> </>
) : null} ) : null}
</> </>

View File

@@ -1,4 +1,4 @@
import { useMemo, useState } from 'react' import { useCallback, useEffect, useMemo, useState } from 'react'
import { ServerType } from './ServerType' import { ServerType } from './ServerType'
import DecoratedInput from '@/Components/Input/DecoratedInput' import DecoratedInput from '@/Components/Input/DecoratedInput'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
@@ -8,22 +8,45 @@ import RadioButtonGroup from '@/Components/RadioButtonGroup/RadioButtonGroup'
import { DefaultHost } from '@standardnotes/snjs' import { DefaultHost } from '@standardnotes/snjs'
type Props = { type Props = {
customServerAddress?: string
handleCustomServerAddressChange: (value: string, websocketUrl?: string) => void
className?: string className?: string
} }
const ServerPicker = ({ className, customServerAddress, handleCustomServerAddressChange }: Props) => { const ServerPicker = ({ className }: Props) => {
const application = useApplication() const application = useApplication()
const [currentType, setCurrentType] = useState<ServerType>('standard') const [currentType, setCurrentType] = useState<ServerType>('standard')
const { server, setServer } = application.accountMenuController
const determineServerType = useCallback(async () => {
const homeServerUrl = await application.homeServer?.getHomeServerUrl()
if (homeServerUrl && server === homeServerUrl) {
setCurrentType('home server')
} else if (server === DefaultHost.Api) {
setCurrentType('standard')
} else {
setCurrentType('custom')
}
}, [application.homeServer, server])
const handleSyncServerChange = useCallback(
(server: string, websocketUrl?: string) => {
setServer(server)
void determineServerType()
application.setCustomHost(server, websocketUrl).catch(console.error)
},
[application, setServer, determineServerType],
)
useEffect(() => {
void determineServerType()
}, [application, server, determineServerType])
const selectTab = async (type: ServerType) => { const selectTab = async (type: ServerType) => {
setCurrentType(type) setCurrentType(type)
if (type === 'standard') { if (type === 'standard') {
handleCustomServerAddressChange(DefaultHost.Api, DefaultHost.WebSocket) handleSyncServerChange(DefaultHost.Api, DefaultHost.WebSocket)
} } else if (type === 'home server') {
if (type === 'home server') {
if (!application.homeServer) { if (!application.homeServer) {
application.alerts application.alerts
.alert('Home server is not running. Please open the prefences and home server tab to start it.') .alert('Home server is not running. Please open the prefences and home server tab to start it.')
@@ -41,7 +64,7 @@ const ServerPicker = ({ className, customServerAddress, handleCustomServerAddres
return return
} }
handleCustomServerAddressChange(homeServerUrl) handleSyncServerChange(homeServerUrl)
} }
} }
@@ -69,8 +92,8 @@ const ServerPicker = ({ className, customServerAddress, handleCustomServerAddres
type="text" type="text"
left={[<Icon type="server" className="text-neutral" />]} left={[<Icon type="server" className="text-neutral" />]}
placeholder={DefaultHost.Api} placeholder={DefaultHost.Api}
value={customServerAddress} value={server}
onChange={handleCustomServerAddressChange} onChange={handleSyncServerChange}
/> />
)} )}
</div> </div>