about summary refs log tree commit diff
path: root/src/lib/hooks
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-10-05 16:44:05 -0700
committerGitHub <noreply@github.com>2023-10-05 16:44:05 -0700
commitbd7db8af26bfbf94a80972671ca714a143bee28e (patch)
treecf022bddc4f6b164bea51aeb3c57479d72b73355 /src/lib/hooks
parent19f8389fc777c7ff41466748f1238f4e0a4b0619 (diff)
downloadvoidsky-bd7db8af26bfbf94a80972671ca714a143bee28e.tar.zst
Improve typeahead search with inclusion of followed users (temporary solution) (#1612)
* Update follows cache to maintain some user info

* Prioritize follows in composer autocomplete

* Clean up logic and add new autocomplete to search

* Update follow hook
Diffstat (limited to 'src/lib/hooks')
-rw-r--r--src/lib/hooks/useFollowProfile.ts (renamed from src/lib/hooks/useFollowDid.ts)24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/hooks/useFollowDid.ts b/src/lib/hooks/useFollowProfile.ts
index 223adb047..6220daba8 100644
--- a/src/lib/hooks/useFollowDid.ts
+++ b/src/lib/hooks/useFollowProfile.ts
@@ -1,11 +1,11 @@
 import React from 'react'
-
+import {AppBskyActorDefs} from '@atproto/api'
 import {useStores} from 'state/index'
 import {FollowState} from 'state/models/cache/my-follows'
 
-export function useFollowDid({did}: {did: string}) {
+export function useFollowProfile(profile: AppBskyActorDefs.ProfileViewBasic) {
   const store = useStores()
-  const state = store.me.follows.getFollowState(did)
+  const state = store.me.follows.getFollowState(profile.did)
 
   return {
     state,
@@ -13,8 +13,10 @@ export function useFollowDid({did}: {did: string}) {
     toggle: React.useCallback(async () => {
       if (state === FollowState.Following) {
         try {
-          await store.agent.deleteFollow(store.me.follows.getFollowUri(did))
-          store.me.follows.removeFollow(did)
+          await store.agent.deleteFollow(
+            store.me.follows.getFollowUri(profile.did),
+          )
+          store.me.follows.removeFollow(profile.did)
           return {
             state: FollowState.NotFollowing,
             following: false,
@@ -25,8 +27,14 @@ export function useFollowDid({did}: {did: string}) {
         }
       } else if (state === FollowState.NotFollowing) {
         try {
-          const res = await store.agent.follow(did)
-          store.me.follows.addFollow(did, res.uri)
+          const res = await store.agent.follow(profile.did)
+          store.me.follows.addFollow(profile.did, {
+            followRecordUri: res.uri,
+            did: profile.did,
+            handle: profile.handle,
+            displayName: profile.displayName,
+            avatar: profile.avatar,
+          })
           return {
             state: FollowState.Following,
             following: true,
@@ -41,6 +49,6 @@ export function useFollowDid({did}: {did: string}) {
         state: FollowState.Unknown,
         following: false,
       }
-    }, [store, did, state]),
+    }, [store, profile, state]),
   }
 }