From ef071c09153a1bb843515dff1598beef7932b093 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 14 Nov 2022 15:02:42 -0600 Subject: [PATCH] Fix issue causing double-loads of notifications --- src/state/models/feed-view.ts | 15 ++++++--------- src/state/models/notifications-view.ts | 5 +++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/state/models/feed-view.ts b/src/state/models/feed-view.ts index 8e180a35..905f7af7 100644 --- a/src/state/models/feed-view.ts +++ b/src/state/models/feed-view.ts @@ -134,9 +134,9 @@ export class FeedModel { isLoading = false isRefreshing = false hasLoaded = false - hasReachedEnd = false error = '' params: GetTimeline.QueryParams | GetAuthorFeed.QueryParams + hasMore = true loadMoreCursor: string | undefined _loadPromise: Promise | undefined _loadMorePromise: Promise | undefined @@ -298,18 +298,15 @@ export class FeedModel { } private async _loadMore() { + if (!this.hasMore) { + return + } this._xLoading() try { const res = await this._getFeed({ before: this.loadMoreCursor, }) - if (res.data.feed.length === 0) { - runInAction(() => { - this.hasReachedEnd = true - }) - } else { - this._appendAll(res) - } + this._appendAll(res) this._xIdle() } catch (e: any) { this._xIdle(`Failed to load feed: ${e.toString()}`) @@ -342,12 +339,12 @@ export class FeedModel { private _replaceAll(res: GetTimeline.Response | GetAuthorFeed.Response) { this.feed.length = 0 - this.hasReachedEnd = false this._appendAll(res) } private _appendAll(res: GetTimeline.Response | GetAuthorFeed.Response) { this.loadMoreCursor = res.data.cursor + this.hasMore = !!this.loadMoreCursor let counter = this.feed.length for (const item of res.data.feed) { this._append(counter++, item) diff --git a/src/state/models/notifications-view.ts b/src/state/models/notifications-view.ts index 43bc0cb4..72cc17f6 100644 --- a/src/state/models/notifications-view.ts +++ b/src/state/models/notifications-view.ts @@ -113,6 +113,7 @@ export class NotificationsViewModel { hasLoaded = false error = '' params: ListNotifications.QueryParams + hasMore = true loadMoreCursor?: string _loadPromise: Promise | undefined _loadMorePromise: Promise | undefined @@ -246,6 +247,9 @@ export class NotificationsViewModel { } private async _loadMore() { + if (!this.hasMore) { + return + } this._xLoading() try { const params = Object.assign({}, this.params, { @@ -291,6 +295,7 @@ export class NotificationsViewModel { private _appendAll(res: ListNotifications.Response) { this.loadMoreCursor = res.data.cursor + this.hasMore = !!this.loadMoreCursor let counter = this.notifications.length for (const item of groupNotifications(res.data.notifications)) { this._append(counter++, item)