about summary refs log tree commit diff
path: root/src/state/index.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-12-05 13:25:04 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-12-05 13:25:04 -0600
commitf27e32e54c3e6a6f7d156cf6c23c11778a7dd316 (patch)
tree484dbd281d938082c0de8ec3ba346ed8af839429 /src/state/index.ts
parent59363181e1c72dcec3a86cf155f12a556e569b8f (diff)
downloadvoidsky-f27e32e54c3e6a6f7d156cf6c23c11778a7dd316.tar.zst
Ensure the UI always renders, even in bad network conditions (close #6)
Diffstat (limited to 'src/state/index.ts')
-rw-r--r--src/state/index.ts16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/state/index.ts b/src/state/index.ts
index 32efea3f3..739742d4a 100644
--- a/src/state/index.ts
+++ b/src/state/index.ts
@@ -27,10 +27,19 @@ export async function setupState() {
     console.error('Failed to load state from storage', e)
   }
 
-  await rootStore.session.setup()
+  console.log('Initial hydrate', rootStore.me)
+  rootStore.session
+    .connect()
+    .then(() => {
+      console.log('Session connected', rootStore.me)
+      return rootStore.fetchStateUpdate()
+    })
+    .catch(e => {
+      console.log('Failed initial connect', e)
+    })
   // @ts-ignore .on() is correct -prf
   api.sessionManager.on('session', () => {
-    if (!api.sessionManager.session && rootStore.session.isAuthed) {
+    if (!api.sessionManager.session && rootStore.session.hasSession) {
       // reset session
       rootStore.session.clear()
     } else if (api.sessionManager.session) {
@@ -44,9 +53,6 @@ export async function setupState() {
     storage.save(ROOT_STATE_STORAGE_KEY, snapshot)
   })
 
-  await rootStore.fetchStateUpdate()
-  console.log(rootStore.me)
-
   // periodic state fetch
   setInterval(() => {
     rootStore.fetchStateUpdate()