Improve the profile preview with "swipe up to view" and local cache optimization (#1096)
* Update the ProfilePreview to use a swipe-up to navigate * Use the profile cache to optimize load performance * Hack to align the header in the profile preview against the screen view * Fix profiles cache logic to ensure cache is used * Fix dark mode on profile preview
This commit is contained in:
parent
1211c353d0
commit
96280d5f1a
7 changed files with 98 additions and 61 deletions
4
src/state/models/cache/profiles-view.ts
vendored
4
src/state/models/cache/profiles-view.ts
vendored
|
@ -45,8 +45,6 @@ export class ProfilesCache {
|
|||
}
|
||||
|
||||
overwrite(did: string, res: GetProfile.Response) {
|
||||
if (this.cache.has(did)) {
|
||||
this.cache.set(did, res)
|
||||
}
|
||||
this.cache.set(did, res)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,12 @@ export class ProfileModel {
|
|||
// =
|
||||
|
||||
async setup() {
|
||||
await this._load()
|
||||
const precache = await this.rootStore.profiles.cache.get(this.params.actor)
|
||||
if (precache) {
|
||||
await this._loadWithCache(precache)
|
||||
} else {
|
||||
await this._load()
|
||||
}
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
|
@ -252,7 +257,7 @@ export class ProfileModel {
|
|||
this._xLoading(isRefreshing)
|
||||
try {
|
||||
const res = await this.rootStore.agent.getProfile(this.params)
|
||||
this.rootStore.profiles.overwrite(this.params.actor, res) // cache invalidation
|
||||
this.rootStore.profiles.overwrite(this.params.actor, res)
|
||||
if (res.data.handle) {
|
||||
this.rootStore.handleResolutions.cache.set(
|
||||
res.data.handle,
|
||||
|
@ -267,6 +272,23 @@ export class ProfileModel {
|
|||
}
|
||||
}
|
||||
|
||||
async _loadWithCache(precache: GetProfile.Response) {
|
||||
// use cached value
|
||||
this._replaceAll(precache)
|
||||
await this._createRichText()
|
||||
this._xIdle()
|
||||
|
||||
// fetch latest
|
||||
try {
|
||||
const res = await this.rootStore.agent.getProfile(this.params)
|
||||
this.rootStore.profiles.overwrite(this.params.actor, res) // cache invalidation
|
||||
this._replaceAll(res)
|
||||
await this._createRichText()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
_replaceAll(res: GetProfile.Response) {
|
||||
this.did = res.data.did
|
||||
this.handle = res.data.handle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue