Fix issue causing double-loads of notifications
parent
bc9be64a4e
commit
ef071c0915
|
@ -134,9 +134,9 @@ export class FeedModel {
|
||||||
isLoading = false
|
isLoading = false
|
||||||
isRefreshing = false
|
isRefreshing = false
|
||||||
hasLoaded = false
|
hasLoaded = false
|
||||||
hasReachedEnd = false
|
|
||||||
error = ''
|
error = ''
|
||||||
params: GetTimeline.QueryParams | GetAuthorFeed.QueryParams
|
params: GetTimeline.QueryParams | GetAuthorFeed.QueryParams
|
||||||
|
hasMore = true
|
||||||
loadMoreCursor: string | undefined
|
loadMoreCursor: string | undefined
|
||||||
_loadPromise: Promise<void> | undefined
|
_loadPromise: Promise<void> | undefined
|
||||||
_loadMorePromise: Promise<void> | undefined
|
_loadMorePromise: Promise<void> | undefined
|
||||||
|
@ -298,18 +298,15 @@ export class FeedModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _loadMore() {
|
private async _loadMore() {
|
||||||
|
if (!this.hasMore) {
|
||||||
|
return
|
||||||
|
}
|
||||||
this._xLoading()
|
this._xLoading()
|
||||||
try {
|
try {
|
||||||
const res = await this._getFeed({
|
const res = await this._getFeed({
|
||||||
before: this.loadMoreCursor,
|
before: this.loadMoreCursor,
|
||||||
})
|
})
|
||||||
if (res.data.feed.length === 0) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.hasReachedEnd = true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this._appendAll(res)
|
this._appendAll(res)
|
||||||
}
|
|
||||||
this._xIdle()
|
this._xIdle()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
||||||
|
@ -342,12 +339,12 @@ export class FeedModel {
|
||||||
|
|
||||||
private _replaceAll(res: GetTimeline.Response | GetAuthorFeed.Response) {
|
private _replaceAll(res: GetTimeline.Response | GetAuthorFeed.Response) {
|
||||||
this.feed.length = 0
|
this.feed.length = 0
|
||||||
this.hasReachedEnd = false
|
|
||||||
this._appendAll(res)
|
this._appendAll(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
private _appendAll(res: GetTimeline.Response | GetAuthorFeed.Response) {
|
private _appendAll(res: GetTimeline.Response | GetAuthorFeed.Response) {
|
||||||
this.loadMoreCursor = res.data.cursor
|
this.loadMoreCursor = res.data.cursor
|
||||||
|
this.hasMore = !!this.loadMoreCursor
|
||||||
let counter = this.feed.length
|
let counter = this.feed.length
|
||||||
for (const item of res.data.feed) {
|
for (const item of res.data.feed) {
|
||||||
this._append(counter++, item)
|
this._append(counter++, item)
|
||||||
|
|
|
@ -113,6 +113,7 @@ export class NotificationsViewModel {
|
||||||
hasLoaded = false
|
hasLoaded = false
|
||||||
error = ''
|
error = ''
|
||||||
params: ListNotifications.QueryParams
|
params: ListNotifications.QueryParams
|
||||||
|
hasMore = true
|
||||||
loadMoreCursor?: string
|
loadMoreCursor?: string
|
||||||
_loadPromise: Promise<void> | undefined
|
_loadPromise: Promise<void> | undefined
|
||||||
_loadMorePromise: Promise<void> | undefined
|
_loadMorePromise: Promise<void> | undefined
|
||||||
|
@ -246,6 +247,9 @@ export class NotificationsViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _loadMore() {
|
private async _loadMore() {
|
||||||
|
if (!this.hasMore) {
|
||||||
|
return
|
||||||
|
}
|
||||||
this._xLoading()
|
this._xLoading()
|
||||||
try {
|
try {
|
||||||
const params = Object.assign({}, this.params, {
|
const params = Object.assign({}, this.params, {
|
||||||
|
@ -291,6 +295,7 @@ export class NotificationsViewModel {
|
||||||
|
|
||||||
private _appendAll(res: ListNotifications.Response) {
|
private _appendAll(res: ListNotifications.Response) {
|
||||||
this.loadMoreCursor = res.data.cursor
|
this.loadMoreCursor = res.data.cursor
|
||||||
|
this.hasMore = !!this.loadMoreCursor
|
||||||
let counter = this.notifications.length
|
let counter = this.notifications.length
|
||||||
for (const item of groupNotifications(res.data.notifications)) {
|
for (const item of groupNotifications(res.data.notifications)) {
|
||||||
this._append(counter++, item)
|
this._append(counter++, item)
|
||||||
|
|
Loading…
Reference in New Issue