Add mock API and reorg code for clarity

This commit is contained in:
Paul Frazee 2022-07-18 15:24:37 -05:00
parent de87ec17d1
commit 1d00f3b984
29 changed files with 356 additions and 168 deletions

48
src/state/models/me.ts Normal file
View file

@ -0,0 +1,48 @@
import {Instance, SnapshotOut, types, flow, getRoot} from 'mobx-state-tree'
import {RootStore} from './root-store'
import {withEnvironment} from '../env'
export const MeModel = types
.model('Me')
.props({
did: types.maybe(types.string),
name: types.maybe(types.string),
displayName: types.maybe(types.string),
description: types.maybe(types.string),
})
.extend(withEnvironment)
.actions(self => ({
load: flow(function* () {
const sess = (getRoot(self) as RootStore).session
if (sess.isAuthed) {
// TODO temporary
const userDb = self.env.adx.mockDb.mainUser
self.did = userDb.did
self.name = userDb.name
const profile = yield self.env.adx
.repo(self.did, true)
.collection('blueskyweb.xyz:Profiles')
.get('Profile', 'profile')
.catch(_ => undefined)
if (profile?.valid) {
self.displayName = profile.value.displayName
self.description = profile.value.description
} else {
self.displayName = ''
self.description = ''
}
} else {
self.did = undefined
self.name = undefined
self.displayName = undefined
self.description = undefined
}
}),
}))
export interface Me extends Instance<typeof MeModel> {}
export interface MeSnapshot extends SnapshotOut<typeof MeModel> {}
export function createDefaultMe() {
return {}
}