diff options
Diffstat (limited to 'src/state/models/ui')
-rw-r--r-- | src/state/models/ui/profile.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/state/models/ui/profile.ts b/src/state/models/ui/profile.ts index 1d4fe28cd..eb38509fb 100644 --- a/src/state/models/ui/profile.ts +++ b/src/state/models/ui/profile.ts @@ -15,6 +15,10 @@ export interface ProfileUiParams { } export class ProfileUiModel { + static LOADING_ITEM = {_reactKey: '__loading__'} + static END_ITEM = {_reactKey: '__end__'} + static EMPTY_ITEM = {_reactKey: '__empty__'} + // data profile: ProfileViewModel feed: FeedModel @@ -76,6 +80,51 @@ export class ProfileUiModel { return this.selectorItems[this.selectedViewIndex] } + get uiItems() { + let arr: any[] = [] + if (this.isInitialLoading) { + arr = arr.concat([ProfileUiModel.LOADING_ITEM]) + } else if (this.currentView.hasError) { + arr = arr.concat([ + { + _reactKey: '__error__', + error: this.currentView.error, + }, + ]) + } else { + if ( + this.selectedView === Sections.Posts || + this.selectedView === Sections.PostsWithReplies + ) { + if (this.feed.hasContent) { + if (this.selectedView === Sections.Posts) { + arr = this.feed.nonReplyFeed + } else { + arr = this.feed.feed.slice() + } + if (!this.feed.hasMore) { + arr = arr.concat([ProfileUiModel.END_ITEM]) + } + } else if (this.feed.isEmpty) { + arr = arr.concat([ProfileUiModel.EMPTY_ITEM]) + } + } else { + arr = arr.concat([ProfileUiModel.EMPTY_ITEM]) + } + } + return arr + } + + get showLoadingMoreFooter() { + if ( + this.selectedView === Sections.Posts || + this.selectedView === Sections.PostsWithReplies + ) { + return this.feed.hasContent && this.feed.hasMore && this.feed.isLoading + } + return false + } + // public api // = |