Skip to content

Commit

Permalink
First pass at a session handler
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Nov 9, 2023
1 parent bd531f2 commit 6aaa6fe
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 26 deletions.
35 changes: 23 additions & 12 deletions src/App.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@ import {Provider as ModalStateProvider} from 'state/modals'
import {Provider as MutedThreadsProvider} from 'state/muted-threads'
import {Provider as InvitesStateProvider} from 'state/invites'
import {Provider as PrefsStateProvider} from 'state/preferences'
import {
Provider as SessionProvider,
useSession,
useSessionApi,
} from 'state/session'

const InnerApp = observer(function AppImpl() {
const session = useSession()
console.log('session', session)
const {resumeSession} = useSessionApi()
const colorMode = useColorMode()
const [rootStore, setRootStore] = useState<RootStoreModel | undefined>(
undefined,
)

// init
useEffect(() => {
resumeSession()
setupState().then(store => {
setRootStore(store)
analytics.init(store)
})
}, [])
}, [resumeSession])

// show nothing prior to init
if (!rootStore) {
Expand Down Expand Up @@ -71,17 +80,19 @@ function App() {
}

return (
<ShellStateProvider>
<PrefsStateProvider>
<MutedThreadsProvider>
<InvitesStateProvider>
<ModalStateProvider>
<InnerApp />
</ModalStateProvider>
</InvitesStateProvider>
</MutedThreadsProvider>
</PrefsStateProvider>
</ShellStateProvider>
<SessionProvider>
<ShellStateProvider>
<PrefsStateProvider>
<MutedThreadsProvider>
<InvitesStateProvider>
<ModalStateProvider>
<InnerApp />
</ModalStateProvider>
</InvitesStateProvider>
</MutedThreadsProvider>
</PrefsStateProvider>
</ShellStateProvider>
</SessionProvider>
)
}

Expand Down
16 changes: 8 additions & 8 deletions src/state/persisted/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type LegacySchema = {
description: string
avatar: string
}
onboarding: {
onboarding?: {
step: string
}
preferences: {
Expand All @@ -56,12 +56,12 @@ type LegacySchema = {
pinnedFeeds: string[]
requireAltTextEnabled: boolean
}
invitedUsers: {
invitedUsers?: {
seenDids: string[]
copiedInvites: string[]
}
mutedThreads: {uris: string[]}
reminders: {lastEmailConfirm: string}
mutedThreads?: {uris: string[]}
reminders?: {lastEmailConfirm: string}
}

const DEPRECATED_ROOT_STATE_STORAGE_KEY = 'root'
Expand All @@ -77,7 +77,7 @@ export function transform(legacy: LegacySchema): Schema {
},
reminders: {
lastEmailConfirm:
legacy.reminders.lastEmailConfirm ||
legacy.reminders?.lastEmailConfirm ||
defaults.reminders.lastEmailConfirm,
},
languagePrefs: {
Expand All @@ -96,13 +96,13 @@ export function transform(legacy: LegacySchema): Schema {
requireAltTextEnabled:
legacy.preferences.requireAltTextEnabled ||
defaults.requireAltTextEnabled,
mutedThreads: legacy.mutedThreads.uris || defaults.mutedThreads,
mutedThreads: legacy.mutedThreads?.uris || defaults.mutedThreads,
invites: {
copiedInvites:
legacy.invitedUsers.copiedInvites || defaults.invites.copiedInvites,
legacy.invitedUsers?.copiedInvites || defaults.invites.copiedInvites,
},
onboarding: {
step: legacy.onboarding.step || defaults.onboarding.step,
step: legacy.onboarding?.step || defaults.onboarding.step,
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/state/persisted/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {z} from 'zod'
import {deviceLocales} from '#/platform/detection'

// only data needed for rendering account page
// TODO agent.resumeSession requires the following fields
const accountSchema = z.object({
service: z.string(),
did: z.string(),
refreshJwt: z.string().optional(),
accessJwt: z.string().optional(),
handle: z.string().optional(),
displayName: z.string().optional(),
aviUrl: z.string().optional(),
handle: z.string(),
refreshJwt: z.string().optional(), // optional because it can expire
accessJwt: z.string().optional(), // optional because it can expire
// displayName: z.string().optional(),
// aviUrl: z.string().optional(),
})

export const schema = z.object({
Expand Down
Loading

0 comments on commit 6aaa6fe

Please sign in to comment.