about summary refs log tree commit diff
path: root/src/state/models/ui/profile.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-03-15 15:46:39 -0500
committerPaul Frazee <pfrazee@gmail.com>2023-03-15 15:46:39 -0500
commit474b4b7840ce1ee625f19ff02f15ca12b3879c55 (patch)
treef8e27a2ecb4b07c65f348e206a014a5f0ba06f29 /src/state/models/ui/profile.ts
parent8a279b8d2cd003755200426e2ab32d0522783744 (diff)
downloadvoidsky-474b4b7840ce1ee625f19ff02f15ca12b3879c55.tar.zst
Optimize and refactor profile rendering a bit
Diffstat (limited to 'src/state/models/ui/profile.ts')
-rw-r--r--src/state/models/ui/profile.ts49
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
   // =