Collection of fixes to list rendering (#127)

* Fix bug that caused endless spinners in profile feeds

* Bundle fetches of suggested actors into one update

* Fixes to suggested follow rendering
This commit is contained in:
Paul Frazee
2023-01-31 17:03:34 -06:00
committed by GitHub
parent 5ccdec1e4f
commit 5d4dea0a5a
3 changed files with 23 additions and 23 deletions
+19 -20
View File
@@ -1,4 +1,4 @@
import {makeAutoObservable} from 'mobx'
import {makeAutoObservable, runInAction} from 'mobx'
import {AppBskyActorGetSuggestions as GetSuggestions} from '@atproto/api'
import {RootStoreModel} from './root-store'
@@ -89,33 +89,32 @@ export class SuggestedActorsViewModel {
this.suggestions = []
}
let res
let totalAdded = 0
let items: SuggestedActor[] = []
do {
res = await this.rootStore.api.app.bsky.actor.getSuggestions({
limit: PAGE_SIZE,
cursor: this.loadMoreCursor,
})
totalAdded += await this._appendAll(res)
} while (totalAdded < PAGE_SIZE && this.hasMore)
this.loadMoreCursor = res.data.cursor
this.hasMore = !!this.loadMoreCursor
items = items.concat(
res.data.actors.filter(actor => {
if (actor.did === this.rootStore.me.did) {
return false // skip self
}
if (actor.myState?.follow) {
return false // skip already-followed users
}
return true
}),
)
} while (items.length < PAGE_SIZE && this.hasMore)
runInAction(() => {
this.suggestions = this.suggestions.concat(items)
})
this._xIdle()
} catch (e: any) {
this._xIdle(e)
}
}
private async _appendAll(res: GetSuggestions.Response) {
this.loadMoreCursor = res.data.cursor
this.hasMore = !!this.loadMoreCursor
const newSuggestions = res.data.actors.filter(actor => {
if (actor.did === this.rootStore.me.did) {
return false // skip self
}
if (actor.myState?.follow) {
return false // skip already-followed users
}
return true
})
this.suggestions = this.suggestions.concat(newSuggestions)
return newSuggestions.length
}
}