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) {
|
if (this._loadMorePromise) {
|
||||||
return this._loadMorePromise
|
return this._loadMorePromise
|
||||||
}
|
}
|
||||||
if (!this.resolvedUri) {
|
this._loadMorePromise = this._load(isRefreshing)
|
||||||
await this._resolveUri()
|
|
||||||
}
|
|
||||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
|
||||||
await this._loadMorePromise
|
await this._loadMorePromise
|
||||||
this._loadMorePromise = undefined
|
this._loadMorePromise = undefined
|
||||||
}
|
}
|
||||||
@@ -106,25 +103,34 @@ export class RepostedByViewModel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _loadMore(isRefreshing = false) {
|
private async _load(replace = false) {
|
||||||
this._xLoading(isRefreshing)
|
this._xLoading(replace)
|
||||||
try {
|
try {
|
||||||
|
if (!this.resolvedUri) {
|
||||||
|
await this._resolveUri()
|
||||||
|
}
|
||||||
const params = Object.assign({}, this.params, {
|
const params = Object.assign({}, this.params, {
|
||||||
uri: this.resolvedUri,
|
uri: this.resolvedUri,
|
||||||
limit: PAGE_SIZE,
|
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)
|
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()
|
this._xIdle()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this._xIdle(e)
|
this._xIdle(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _replaceAll(res: GetRepostedBy.Response) {
|
||||||
|
this.repostedBy = []
|
||||||
|
this._appendAll(res)
|
||||||
|
}
|
||||||
|
|
||||||
private _appendAll(res: GetRepostedBy.Response) {
|
private _appendAll(res: GetRepostedBy.Response) {
|
||||||
this.loadMoreCursor = res.data.cursor
|
this.loadMoreCursor = res.data.cursor
|
||||||
this.hasMore = !!this.loadMoreCursor
|
this.hasMore = !!this.loadMoreCursor
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export class SuggestedActorsViewModel {
|
|||||||
if (this._loadMorePromise) {
|
if (this._loadMorePromise) {
|
||||||
return this._loadMorePromise
|
return this._loadMorePromise
|
||||||
}
|
}
|
||||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
this._loadMorePromise = this._load(isRefreshing)
|
||||||
await this._loadMorePromise
|
await this._loadMorePromise
|
||||||
this._loadMorePromise = undefined
|
this._loadMorePromise = undefined
|
||||||
}
|
}
|
||||||
@@ -80,17 +80,18 @@ export class SuggestedActorsViewModel {
|
|||||||
// loader functions
|
// loader functions
|
||||||
// =
|
// =
|
||||||
|
|
||||||
private async _loadMore(isRefreshing = false) {
|
private async _load(replace = false) {
|
||||||
if (!this.hasMore) {
|
if (!replace && !this.hasMore) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this._xLoading(isRefreshing)
|
this._xLoading(replace)
|
||||||
try {
|
try {
|
||||||
if (this.isRefreshing) {
|
let items: SuggestedActor[] = this.suggestions
|
||||||
this.suggestions = []
|
if (replace) {
|
||||||
|
items = []
|
||||||
|
this.loadMoreCursor = undefined
|
||||||
}
|
}
|
||||||
let res
|
let res
|
||||||
let items: SuggestedActor[] = []
|
|
||||||
do {
|
do {
|
||||||
res = await this.rootStore.api.app.bsky.actor.getSuggestions({
|
res = await this.rootStore.api.app.bsky.actor.getSuggestions({
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
@@ -111,7 +112,7 @@ export class SuggestedActorsViewModel {
|
|||||||
)
|
)
|
||||||
} while (items.length < PAGE_SIZE && this.hasMore)
|
} while (items.length < PAGE_SIZE && this.hasMore)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.suggestions = this.suggestions.concat(items)
|
this.suggestions = items
|
||||||
})
|
})
|
||||||
this._xIdle()
|
this._xIdle()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export class UserFollowersViewModel {
|
|||||||
if (this._loadMorePromise) {
|
if (this._loadMorePromise) {
|
||||||
return this._loadMorePromise
|
return this._loadMorePromise
|
||||||
}
|
}
|
||||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
this._loadMorePromise = this._load(isRefreshing)
|
||||||
await this._loadMorePromise
|
await this._loadMorePromise
|
||||||
this._loadMorePromise = undefined
|
this._loadMorePromise = undefined
|
||||||
}
|
}
|
||||||
@@ -94,28 +94,34 @@ export class UserFollowersViewModel {
|
|||||||
// loader functions
|
// loader functions
|
||||||
// =
|
// =
|
||||||
|
|
||||||
private async _loadMore(isRefreshing = false) {
|
private async _load(replace = false) {
|
||||||
if (!this.hasMore) {
|
if (!replace && !this.hasMore) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this._xLoading(isRefreshing)
|
this._xLoading(replace)
|
||||||
try {
|
try {
|
||||||
const params = Object.assign({}, this.params, {
|
const params = Object.assign({}, this.params, {
|
||||||
limit: PAGE_SIZE,
|
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)
|
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()
|
this._xIdle()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this._xIdle(e)
|
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.loadMoreCursor = res.data.cursor
|
||||||
this.hasMore = !!this.loadMoreCursor
|
this.hasMore = !!this.loadMoreCursor
|
||||||
this.followers = this.followers.concat(res.data.followers)
|
this.followers = this.followers.concat(res.data.followers)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export class UserFollowsViewModel {
|
|||||||
if (this._loadMorePromise) {
|
if (this._loadMorePromise) {
|
||||||
return this._loadMorePromise
|
return this._loadMorePromise
|
||||||
}
|
}
|
||||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
this._loadMorePromise = this._load(isRefreshing)
|
||||||
await this._loadMorePromise
|
await this._loadMorePromise
|
||||||
this._loadMorePromise = undefined
|
this._loadMorePromise = undefined
|
||||||
}
|
}
|
||||||
@@ -94,28 +94,34 @@ export class UserFollowsViewModel {
|
|||||||
// loader functions
|
// loader functions
|
||||||
// =
|
// =
|
||||||
|
|
||||||
private async _loadMore(isRefreshing = false) {
|
private async _load(replace = false) {
|
||||||
if (!this.hasMore) {
|
if (!replace && !this.hasMore) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this._xLoading(isRefreshing)
|
this._xLoading(replace)
|
||||||
try {
|
try {
|
||||||
const params = Object.assign({}, this.params, {
|
const params = Object.assign({}, this.params, {
|
||||||
limit: PAGE_SIZE,
|
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)
|
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()
|
this._xIdle()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this._xIdle(e)
|
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.loadMoreCursor = res.data.cursor
|
||||||
this.hasMore = !!this.loadMoreCursor
|
this.hasMore = !!this.loadMoreCursor
|
||||||
this.follows = this.follows.concat(res.data.follows)
|
this.follows = this.follows.concat(res.data.follows)
|
||||||
|
|||||||
@@ -59,10 +59,7 @@ export class VotesViewModel {
|
|||||||
if (this._loadMorePromise) {
|
if (this._loadMorePromise) {
|
||||||
return this._loadMorePromise
|
return this._loadMorePromise
|
||||||
}
|
}
|
||||||
if (!this.resolvedUri) {
|
this._loadMorePromise = this._load(isRefreshing)
|
||||||
await this._resolveUri()
|
|
||||||
}
|
|
||||||
this._loadMorePromise = this._loadMore(isRefreshing)
|
|
||||||
await this._loadMorePromise
|
await this._loadMorePromise
|
||||||
this._loadMorePromise = undefined
|
this._loadMorePromise = undefined
|
||||||
}
|
}
|
||||||
@@ -103,25 +100,37 @@ export class VotesViewModel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _loadMore(isRefreshing = false) {
|
private async _load(replace = false) {
|
||||||
this._xLoading(isRefreshing)
|
if (!replace && !this.hasMore) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this._xLoading(replace)
|
||||||
try {
|
try {
|
||||||
|
if (!this.resolvedUri) {
|
||||||
|
await this._resolveUri()
|
||||||
|
}
|
||||||
const params = Object.assign({}, this.params, {
|
const params = Object.assign({}, this.params, {
|
||||||
uri: this.resolvedUri,
|
uri: this.resolvedUri,
|
||||||
limit: PAGE_SIZE,
|
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)
|
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()
|
this._xIdle()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this._xIdle(e)
|
this._xIdle(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _replaceAll(res: GetVotes.Response) {
|
||||||
|
this.votes = []
|
||||||
|
this._appendAll(res)
|
||||||
|
}
|
||||||
|
|
||||||
private _appendAll(res: GetVotes.Response) {
|
private _appendAll(res: GetVotes.Response) {
|
||||||
this.loadMoreCursor = res.data.cursor
|
this.loadMoreCursor = res.data.cursor
|
||||||
this.hasMore = !!this.loadMoreCursor
|
this.hasMore = !!this.loadMoreCursor
|
||||||
|
|||||||
Reference in New Issue
Block a user