about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-08-22 14:30:51 -0500
committerGitHub <noreply@github.com>2023-08-22 12:30:51 -0700
commit2b13dc0f3abfdb0eca03150bd77d773bbb26ebd4 (patch)
treeb17e377c3c733092927f82f309d881194c4aa1de /src
parent548ec6c82d114f96c431a4e0f162e8360bfd22f4 (diff)
downloadvoidsky-2b13dc0f3abfdb0eca03150bd77d773bbb26ebd4.tar.zst
Add likes tab (#1227)
* add likes tab

(cherry picked from commit 6c5ffd964ca0b185ddfc37088d82712a006a1163)

* only show Likes tab to authenticated user

(cherry picked from commit ecc1254411d760158b6d7a4c5f05d940db872dfc)

* Bump @atproto/api@0.6.5

* fix types

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/state/models/feeds/posts.ts9
-rw-r--r--src/state/models/ui/profile.ts73
2 files changed, 57 insertions, 25 deletions
diff --git a/src/state/models/feeds/posts.ts b/src/state/models/feeds/posts.ts
index 93add8102..8bc75daa4 100644
--- a/src/state/models/feeds/posts.ts
+++ b/src/state/models/feeds/posts.ts
@@ -3,6 +3,7 @@ import {
   AppBskyFeedGetTimeline as GetTimeline,
   AppBskyFeedGetAuthorFeed as GetAuthorFeed,
   AppBskyFeedGetFeed as GetCustomFeed,
+  AppBskyFeedGetActorLikes as GetActorLikes,
 } from '@atproto/api'
 import AwaitLock from 'await-lock'
 import {bundleAsync} from 'lib/async/bundle'
@@ -57,7 +58,7 @@ export class PostsFeedModel {
 
   constructor(
     public rootStore: RootStoreModel,
-    public feedType: 'home' | 'author' | 'custom',
+    public feedType: 'home' | 'author' | 'custom' | 'likes',
     params: QueryParams,
     options?: Options,
   ) {
@@ -429,10 +430,14 @@ export class PostsFeedModel {
         res.data.feed = res.data.feed.slice(0, params.limit)
       }
       return res
-    } else {
+    } else if (this.feedType === 'author') {
       return this.rootStore.agent.getAuthorFeed(
         params as GetAuthorFeed.QueryParams,
       )
+    } else {
+      return this.rootStore.agent.getActorLikes(
+        params as GetActorLikes.QueryParams,
+      )
     }
   }
 }
diff --git a/src/state/models/ui/profile.ts b/src/state/models/ui/profile.ts
index e026a27fc..436ab313b 100644
--- a/src/state/models/ui/profile.ts
+++ b/src/state/models/ui/profile.ts
@@ -9,6 +9,7 @@ export enum Sections {
   PostsNoReplies = 'Posts',
   PostsWithReplies = 'Posts & replies',
   PostsWithMedia = 'Media',
+  Likes = 'Likes',
   CustomAlgorithms = 'Feeds',
   Lists = 'Lists',
 }
@@ -22,6 +23,8 @@ export class ProfileUiModel {
   static END_ITEM = {_reactKey: '__end__'}
   static EMPTY_ITEM = {_reactKey: '__empty__'}
 
+  isAuthenticatedUser = false
+
   // data
   profile: ProfileModel
   feed: PostsFeedModel
@@ -57,7 +60,8 @@ export class ProfileUiModel {
     if (
       this.selectedView === Sections.PostsNoReplies ||
       this.selectedView === Sections.PostsWithReplies ||
-      this.selectedView === Sections.PostsWithMedia
+      this.selectedView === Sections.PostsWithMedia ||
+      this.selectedView === Sections.Likes
     ) {
       return this.feed
     } else if (this.selectedView === Sections.Lists) {
@@ -83,7 +87,8 @@ export class ProfileUiModel {
       Sections.PostsNoReplies,
       Sections.PostsWithReplies,
       Sections.PostsWithMedia,
-    ]
+      this.isAuthenticatedUser && Sections.Likes,
+    ].filter(Boolean) as string[]
     if (this.algos.hasLoaded && !this.algos.isEmpty) {
       items.push(Sections.CustomAlgorithms)
     }
@@ -117,7 +122,8 @@ export class ProfileUiModel {
       if (
         this.selectedView === Sections.PostsNoReplies ||
         this.selectedView === Sections.PostsWithReplies ||
-        this.selectedView === Sections.PostsWithMedia
+        this.selectedView === Sections.PostsWithMedia ||
+        this.selectedView === Sections.Likes
       ) {
         if (this.feed.hasContent) {
           arr = this.feed.slices.slice()
@@ -151,7 +157,8 @@ export class ProfileUiModel {
     if (
       this.selectedView === Sections.PostsNoReplies ||
       this.selectedView === Sections.PostsWithReplies ||
-      this.selectedView === Sections.PostsWithMedia
+      this.selectedView === Sections.PostsWithMedia ||
+      this.selectedView === Sections.Likes
     ) {
       return this.feed.hasContent && this.feed.hasMore && this.feed.isLoading
     } else if (this.selectedView === Sections.Lists) {
@@ -169,27 +176,45 @@ export class ProfileUiModel {
 
     this.selectedViewIndex = index
 
-    let filter = 'posts_no_replies'
-    if (this.selectedView === Sections.PostsWithReplies) {
-      filter = 'posts_with_replies'
-    } else if (this.selectedView === Sections.PostsWithMedia) {
-      filter = 'posts_with_media'
-    }
+    if (
+      this.selectedView === Sections.PostsNoReplies ||
+      this.selectedView === Sections.PostsWithReplies ||
+      this.selectedView === Sections.PostsWithMedia
+    ) {
+      let filter = 'posts_no_replies'
+      if (this.selectedView === Sections.PostsWithReplies) {
+        filter = 'posts_with_replies'
+      } else if (this.selectedView === Sections.PostsWithMedia) {
+        filter = 'posts_with_media'
+      }
 
-    this.feed = new PostsFeedModel(
-      this.rootStore,
-      'author',
-      {
-        actor: this.params.user,
-        limit: 10,
-        filter,
-      },
-      {
-        isSimpleFeed: ['posts_with_media'].includes(filter),
-      },
-    )
+      this.feed = new PostsFeedModel(
+        this.rootStore,
+        'author',
+        {
+          actor: this.params.user,
+          limit: 10,
+          filter,
+        },
+        {
+          isSimpleFeed: ['posts_with_media'].includes(filter),
+        },
+      )
+
+      this.feed.setup()
+    } else if (this.selectedView === Sections.Likes) {
+      this.feed = new PostsFeedModel(
+        this.rootStore,
+        'likes',
+        {
+          actor: this.params.user,
+          limit: 10,
+        },
+        {
+          isSimpleFeed: true,
+        },
+      )
 
-    if (this.currentView instanceof PostsFeedModel) {
       this.feed.setup()
     }
   }
@@ -203,6 +228,8 @@ export class ProfileUiModel {
         .setup()
         .catch(err => this.rootStore.log.error('Failed to fetch feed', err)),
     ])
+    this.isAuthenticatedUser =
+      this.profile.did === this.rootStore.session.currentSession?.did
     this.algos.refresh()
     // HACK: need to use the DID as a param, not the username -prf
     this.lists.source = this.profile.did