Skip to content

Commit 04106b3

Browse files
committed
chore: fix server selection ux [skip e2e]
1 parent 23efad8 commit 04106b3

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

packages/snjs/lib/Services/Sync/SyncService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ export class SyncService
940940
return
941941
}
942942

943-
if (options.checkIntegrity) {
943+
if (options.checkIntegrity && online) {
944944
await this.notifyEventSync(SyncEvent.SyncRequestsIntegrityCheck, {
945945
source: options.source as SyncSource,
946946
})

packages/web/src/javascripts/Application/Device/DesktopManager.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ export class DesktopManager
5050
void this.backups.importWatchedDirectoryChanges(changes)
5151
}
5252

53-
async handleHomeServerStarted(serverUrl: string): Promise<void> {
54-
const userIsSignedIn = this.application.sessions.isSignedIn()
55-
if (!userIsSignedIn) {
56-
await this.application.setCustomHost(serverUrl)
57-
}
58-
}
53+
async handleHomeServerStarted(_serverUrl: string): Promise<void> {}
5954

6055
beginTextBackupsTimer() {
6156
if (this.textBackupsInterval) {

packages/web/src/javascripts/Components/AccountMenu/AdvancedOptions.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DecoratedInput from '@/Components/Input/DecoratedInput'
55
import Icon from '@/Components/Icon/Icon'
66
import { useApplication } from '../ApplicationProvider'
77
import ServerPicker from './ServerPicker/ServerPicker'
8+
import { DefaultHost } from '@standardnotes/snjs'
89

910
type Props = {
1011
disabled?: boolean
@@ -23,8 +24,9 @@ const AdvancedOptions: FunctionComponent<Props> = ({
2324
}) => {
2425
const application = useApplication()
2526

26-
const { server, setServer } = application.accountMenuController
27-
const [showAdvanced, setShowAdvanced] = useState(false)
27+
const { server } = application.accountMenuController
28+
29+
const [showAdvanced, setShowAdvanced] = useState(server !== DefaultHost.Api)
2830

2931
const [isPrivateUsername, setIsPrivateUsername] = useState(false)
3032
const [privateUsername, setPrivateUsername] = useState('')
@@ -34,6 +36,14 @@ const AdvancedOptions: FunctionComponent<Props> = ({
3436

3537
const [isStrictSignin, setIsStrictSignin] = useState(false)
3638

39+
useEffect(() => {
40+
void application.homeServer?.isHomeServerRunning().then((isRunning) => {
41+
if (isRunning) {
42+
setShowAdvanced(true)
43+
}
44+
})
45+
}, [application.homeServer])
46+
3747
useEffect(() => {
3848
const recomputePrivateUsername = async () => {
3949
const identifier = await application.computePrivateUsername(privateUsername)
@@ -85,14 +95,6 @@ const AdvancedOptions: FunctionComponent<Props> = ({
8595
[onRecoveryCodesChange],
8696
)
8797

88-
const handleSyncServerChange = useCallback(
89-
(server: string, websocketUrl?: string) => {
90-
setServer(server)
91-
application.setCustomHost(server, websocketUrl).catch(console.error)
92-
},
93-
[application, setServer],
94-
)
95-
9698
const handleStrictSigninChange = useCallback(() => {
9799
const newValue = !isStrictSignin
98100
setIsStrictSignin(newValue)
@@ -194,7 +196,7 @@ const AdvancedOptions: FunctionComponent<Props> = ({
194196
</>
195197
)}
196198
</div>
197-
<ServerPicker customServerAddress={server} handleCustomServerAddressChange={handleSyncServerChange} />
199+
<ServerPicker />
198200
</>
199201
) : null}
200202
</>

packages/web/src/javascripts/Components/AccountMenu/ServerPicker/ServerPicker.tsx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useState } from 'react'
1+
import { useCallback, useEffect, useMemo, useState } from 'react'
22
import { ServerType } from './ServerType'
33
import DecoratedInput from '@/Components/Input/DecoratedInput'
44
import Icon from '@/Components/Icon/Icon'
@@ -8,22 +8,45 @@ import RadioButtonGroup from '@/Components/RadioButtonGroup/RadioButtonGroup'
88
import { DefaultHost } from '@standardnotes/snjs'
99

1010
type Props = {
11-
customServerAddress?: string
12-
handleCustomServerAddressChange: (value: string, websocketUrl?: string) => void
1311
className?: string
1412
}
1513

16-
const ServerPicker = ({ className, customServerAddress, handleCustomServerAddressChange }: Props) => {
14+
const ServerPicker = ({ className }: Props) => {
1715
const application = useApplication()
1816

1917
const [currentType, setCurrentType] = useState<ServerType>('standard')
2018

19+
const { server, setServer } = application.accountMenuController
20+
21+
const determineServerType = useCallback(async () => {
22+
const homeServerUrl = await application.homeServer?.getHomeServerUrl()
23+
if (homeServerUrl && server === homeServerUrl) {
24+
setCurrentType('home server')
25+
} else if (server === DefaultHost.Api) {
26+
setCurrentType('standard')
27+
} else {
28+
setCurrentType('custom')
29+
}
30+
}, [application.homeServer, server])
31+
32+
const handleSyncServerChange = useCallback(
33+
(server: string, websocketUrl?: string) => {
34+
setServer(server)
35+
void determineServerType()
36+
application.setCustomHost(server, websocketUrl).catch(console.error)
37+
},
38+
[application, setServer, determineServerType],
39+
)
40+
41+
useEffect(() => {
42+
void determineServerType()
43+
}, [application, server, determineServerType])
44+
2145
const selectTab = async (type: ServerType) => {
2246
setCurrentType(type)
2347
if (type === 'standard') {
24-
handleCustomServerAddressChange(DefaultHost.Api, DefaultHost.WebSocket)
25-
}
26-
if (type === 'home server') {
48+
handleSyncServerChange(DefaultHost.Api, DefaultHost.WebSocket)
49+
} else if (type === 'home server') {
2750
if (!application.homeServer) {
2851
application.alerts
2952
.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
4164
return
4265
}
4366

44-
handleCustomServerAddressChange(homeServerUrl)
67+
handleSyncServerChange(homeServerUrl)
4568
}
4669
}
4770

@@ -69,8 +92,8 @@ const ServerPicker = ({ className, customServerAddress, handleCustomServerAddres
6992
type="text"
7093
left={[<Icon type="server" className="text-neutral" />]}
7194
placeholder={DefaultHost.Api}
72-
value={customServerAddress}
73-
onChange={handleCustomServerAddressChange}
95+
value={server}
96+
onChange={handleSyncServerChange}
7497
/>
7598
)}
7699
</div>

0 commit comments

Comments
 (0)