personal web client for Bluesky
typescript solidjs bluesky atcute

refactor: reload instead when switching accounts

mary.my.id 7da7bb17 bfcb4719

verified
Changed files
+13 -27
src
lib
states
+13 -27
src/lib/states/session.tsx
··· 22 22 23 23 import { type Labeler, attachLabelerHeaders } from '../atproto/labeler'; 24 24 import { makeAbortable } from '../hooks/abortable'; 25 - import { createReactiveLocalStorage, isExternalWriting } from '../hooks/local-storage'; 25 + import { createReactiveLocalStorage } from '../hooks/local-storage'; 26 26 import type { PerAccountPreferenceSchema } from '../preferences/account'; 27 27 import type { AccountData } from '../preferences/sessions'; 28 28 import { assert } from '../utils/invariant'; ··· 144 144 return; 145 145 } 146 146 147 + // If we already have a session, reload... 148 + if (state()) { 149 + batch(() => { 150 + sessions.active = did; 151 + sessions.accounts = [account, ...sessions.accounts.filter((acc) => acc.did !== did)]; 152 + 153 + location.reload(); 154 + }); 155 + 156 + return; 157 + } 158 + 147 159 const signal = getSignal(); 148 160 149 161 const session = await oauthSessions.get(did, { allowStale: true }); ··· 195 207 } 196 208 }, 197 209 }; 198 - 199 - createEffect(() => { 200 - const active = sessions.active; 201 - 202 - // Only run this on external changes 203 - if (isExternalWriting) { 204 - const untrackedState = untrack(state); 205 - 206 - if (active) { 207 - if (active !== untrackedState?.did) { 208 - // Current active account doesn't match what we have 209 - 210 - // Still logged in, so log out of this one 211 - if (untrackedState) { 212 - replaceState(undefined); 213 - } 214 - 215 - // Try to resume from this new account if we have it. 216 - context.resumeSession(active); 217 - } 218 - } else if (untrackedState) { 219 - // No active account yet we have a session, log out 220 - replaceState(undefined); 221 - } 222 - } 223 - }); 224 210 225 211 return <Context.Provider value={context}>{props.children}</Context.Provider>; 226 212 };