Fix refresh behavior around a series of models (repost, graph, vote) (#163)
* Fix refresh behavior around a series of models (repost, graph, vote) * Fix cursor behavior in reposted-by view
This commit is contained in:
@@ -62,10 +62,7 @@ export class RepostedByViewModel {
|
||||
if (this._loadMorePromise) {
|
||||
return this._loadMorePromise
|
||||
}
|
||||
if (!this.resolvedUri) {
|
||||
await this._resolveUri()
|
||||
}
|
||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
||||
this._loadMorePromise = this._load(isRefreshing)
|
||||
await this._loadMorePromise
|
||||
this._loadMorePromise = undefined
|
||||
}
|
||||
@@ -106,25 +103,34 @@ export class RepostedByViewModel {
|
||||
})
|
||||
}
|
||||
|
||||
private async _loadMore(isRefreshing = false) {
|
||||
this._xLoading(isRefreshing)
|
||||
private async _load(replace = false) {
|
||||
this._xLoading(replace)
|
||||
try {
|
||||
if (!this.resolvedUri) {
|
||||
await this._resolveUri()
|
||||
}
|
||||
const params = Object.assign({}, this.params, {
|
||||
uri: this.resolvedUri,
|
||||
limit: PAGE_SIZE,
|
||||
before: this.loadMoreCursor,
|
||||
before: replace ? undefined : this.loadMoreCursor,
|
||||
})
|
||||
if (this.isRefreshing) {
|
||||
this.repostedBy = []
|
||||
}
|
||||
const res = await this.rootStore.api.app.bsky.feed.getRepostedBy(params)
|
||||
await this._appendAll(res)
|
||||
if (replace) {
|
||||
this._replaceAll(res)
|
||||
} else {
|
||||
this._appendAll(res)
|
||||
}
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
private _replaceAll(res: GetRepostedBy.Response) {
|
||||
this.repostedBy = []
|
||||
this._appendAll(res)
|
||||
}
|
||||
|
||||
private _appendAll(res: GetRepostedBy.Response) {
|
||||
this.loadMoreCursor = res.data.cursor
|
||||
this.hasMore = !!this.loadMoreCursor
|
||||
|
||||
@@ -53,7 +53,7 @@ export class SuggestedActorsViewModel {
|
||||
if (this._loadMorePromise) {
|
||||
return this._loadMorePromise
|
||||
}
|
||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
||||
this._loadMorePromise = this._load(isRefreshing)
|
||||
await this._loadMorePromise
|
||||
this._loadMorePromise = undefined
|
||||
}
|
||||
@@ -80,17 +80,18 @@ export class SuggestedActorsViewModel {
|
||||
// loader functions
|
||||
// =
|
||||
|
||||
private async _loadMore(isRefreshing = false) {
|
||||
if (!this.hasMore) {
|
||||
private async _load(replace = false) {
|
||||
if (!replace && !this.hasMore) {
|
||||
return
|
||||
}
|
||||
this._xLoading(isRefreshing)
|
||||
this._xLoading(replace)
|
||||
try {
|
||||
if (this.isRefreshing) {
|
||||
this.suggestions = []
|
||||
let items: SuggestedActor[] = this.suggestions
|
||||
if (replace) {
|
||||
items = []
|
||||
this.loadMoreCursor = undefined
|
||||
}
|
||||
let res
|
||||
let items: SuggestedActor[] = []
|
||||
do {
|
||||
res = await this.rootStore.api.app.bsky.actor.getSuggestions({
|
||||
limit: PAGE_SIZE,
|
||||
@@ -111,7 +112,7 @@ export class SuggestedActorsViewModel {
|
||||
)
|
||||
} while (items.length < PAGE_SIZE && this.hasMore)
|
||||
runInAction(() => {
|
||||
this.suggestions = this.suggestions.concat(items)
|
||||
this.suggestions = items
|
||||
})
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -67,7 +67,7 @@ export class UserFollowersViewModel {
|
||||
if (this._loadMorePromise) {
|
||||
return this._loadMorePromise
|
||||
}
|
||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
||||
this._loadMorePromise = this._load(isRefreshing)
|
||||
await this._loadMorePromise
|
||||
this._loadMorePromise = undefined
|
||||
}
|
||||
@@ -94,28 +94,34 @@ export class UserFollowersViewModel {
|
||||
// loader functions
|
||||
// =
|
||||
|
||||
private async _loadMore(isRefreshing = false) {
|
||||
if (!this.hasMore) {
|
||||
private async _load(replace = false) {
|
||||
if (!replace && !this.hasMore) {
|
||||
return
|
||||
}
|
||||
this._xLoading(isRefreshing)
|
||||
this._xLoading(replace)
|
||||
try {
|
||||
const params = Object.assign({}, this.params, {
|
||||
limit: PAGE_SIZE,
|
||||
before: this.loadMoreCursor,
|
||||
before: replace ? undefined : this.loadMoreCursor,
|
||||
})
|
||||
if (this.isRefreshing) {
|
||||
this.followers = []
|
||||
}
|
||||
const res = await this.rootStore.api.app.bsky.graph.getFollowers(params)
|
||||
await this._appendAll(res)
|
||||
if (replace) {
|
||||
this._replaceAll(res)
|
||||
} else {
|
||||
this._appendAll(res)
|
||||
}
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
private async _appendAll(res: GetFollowers.Response) {
|
||||
private _replaceAll(res: GetFollowers.Response) {
|
||||
this.followers = []
|
||||
this._appendAll(res)
|
||||
}
|
||||
|
||||
private _appendAll(res: GetFollowers.Response) {
|
||||
this.loadMoreCursor = res.data.cursor
|
||||
this.hasMore = !!this.loadMoreCursor
|
||||
this.followers = this.followers.concat(res.data.followers)
|
||||
|
||||
@@ -67,7 +67,7 @@ export class UserFollowsViewModel {
|
||||
if (this._loadMorePromise) {
|
||||
return this._loadMorePromise
|
||||
}
|
||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
||||
this._loadMorePromise = this._load(isRefreshing)
|
||||
await this._loadMorePromise
|
||||
this._loadMorePromise = undefined
|
||||
}
|
||||
@@ -94,28 +94,34 @@ export class UserFollowsViewModel {
|
||||
// loader functions
|
||||
// =
|
||||
|
||||
private async _loadMore(isRefreshing = false) {
|
||||
if (!this.hasMore) {
|
||||
private async _load(replace = false) {
|
||||
if (!replace && !this.hasMore) {
|
||||
return
|
||||
}
|
||||
this._xLoading(isRefreshing)
|
||||
this._xLoading(replace)
|
||||
try {
|
||||
const params = Object.assign({}, this.params, {
|
||||
limit: PAGE_SIZE,
|
||||
before: this.loadMoreCursor,
|
||||
before: replace ? undefined : this.loadMoreCursor,
|
||||
})
|
||||
if (this.isRefreshing) {
|
||||
this.follows = []
|
||||
}
|
||||
const res = await this.rootStore.api.app.bsky.graph.getFollows(params)
|
||||
await this._appendAll(res)
|
||||
if (replace) {
|
||||
this._replaceAll(res)
|
||||
} else {
|
||||
this._appendAll(res)
|
||||
}
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
private async _appendAll(res: GetFollows.Response) {
|
||||
private _replaceAll(res: GetFollows.Response) {
|
||||
this.follows = []
|
||||
this._appendAll(res)
|
||||
}
|
||||
|
||||
private _appendAll(res: GetFollows.Response) {
|
||||
this.loadMoreCursor = res.data.cursor
|
||||
this.hasMore = !!this.loadMoreCursor
|
||||
this.follows = this.follows.concat(res.data.follows)
|
||||
|
||||
@@ -59,10 +59,7 @@ export class VotesViewModel {
|
||||
if (this._loadMorePromise) {
|
||||
return this._loadMorePromise
|
||||
}
|
||||
if (!this.resolvedUri) {
|
||||
await this._resolveUri()
|
||||
}
|
||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
||||
this._loadMorePromise = this._load(isRefreshing)
|
||||
await this._loadMorePromise
|
||||
this._loadMorePromise = undefined
|
||||
}
|
||||
@@ -103,25 +100,37 @@ export class VotesViewModel {
|
||||
})
|
||||
}
|
||||
|
||||
private async _loadMore(isRefreshing = false) {
|
||||
this._xLoading(isRefreshing)
|
||||
private async _load(replace = false) {
|
||||
if (!replace && !this.hasMore) {
|
||||
return
|
||||
}
|
||||
this._xLoading(replace)
|
||||
try {
|
||||
if (!this.resolvedUri) {
|
||||
await this._resolveUri()
|
||||
}
|
||||
const params = Object.assign({}, this.params, {
|
||||
uri: this.resolvedUri,
|
||||
limit: PAGE_SIZE,
|
||||
before: this.loadMoreCursor,
|
||||
before: replace ? undefined : this.loadMoreCursor,
|
||||
})
|
||||
if (this.isRefreshing) {
|
||||
this.votes = []
|
||||
}
|
||||
const res = await this.rootStore.api.app.bsky.feed.getVotes(params)
|
||||
this._appendAll(res)
|
||||
if (replace) {
|
||||
this._replaceAll(res)
|
||||
} else {
|
||||
this._appendAll(res)
|
||||
}
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
private _replaceAll(res: GetVotes.Response) {
|
||||
this.votes = []
|
||||
this._appendAll(res)
|
||||
}
|
||||
|
||||
private _appendAll(res: GetVotes.Response) {
|
||||
this.loadMoreCursor = res.data.cursor
|
||||
this.hasMore = !!this.loadMoreCursor
|
||||
|
||||
Reference in New Issue
Block a user