From 9f4b5fba4f453eda9a8c98f72fd41a2f20ed4389 Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Tue, 4 Oct 2022 10:18:35 -0500
Subject: Choose mention candidates from follows

---
 src/view/com/modals/ComposePost.tsx | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

(limited to 'src/view/com/modals/ComposePost.tsx')

diff --git a/src/view/com/modals/ComposePost.tsx b/src/view/com/modals/ComposePost.tsx
index 1d6f9c4e4..510900b60 100644
--- a/src/view/com/modals/ComposePost.tsx
+++ b/src/view/com/modals/ComposePost.tsx
@@ -16,14 +16,25 @@ const WARNING_TEXT_LENGTH = 200
 const DANGER_TEXT_LENGTH = 255
 export const snapPoints = ['100%']
 
-const DEBUG_USERNAMES = ['alice.test', 'bob.test', 'carol.test']
-
 export function Component({replyTo}: {replyTo?: string}) {
   const store = useStores()
   const [error, setError] = useState('')
   const [text, setText] = useState('')
+  const [followedUsers, setFollowedUsers] = useState<
+    undefined | GetUserFollows.OutputSchema['follows']
+  >(undefined)
   const [autocompleteOptions, setAutocompleteOptions] = useState<string[]>([])
 
+  useEffect(() => {
+    store.api.todo.social
+      .getUserFollows({
+        user: store.me.did || '',
+      })
+      .then(res => {
+        setFollowedUsers(res.data.follows)
+      })
+  })
+
   const onChangeText = (newText: string) => {
     if (newText.length > MAX_TEXT_LENGTH) {
       newText = newText.slice(0, MAX_TEXT_LENGTH)
@@ -31,9 +42,13 @@ export function Component({replyTo}: {replyTo?: string}) {
     setText(newText)
 
     const prefix = extractTextAutocompletePrefix(newText)
-    if (typeof prefix === 'string') {
+    if (typeof prefix === 'string' && followedUsers) {
       setAutocompleteOptions(
-        DEBUG_USERNAMES.filter(name => name.includes(prefix)),
+        [prefix].concat(
+          followedUsers
+            .filter(user => user.name.startsWith(prefix))
+            .map(user => user.name),
+        ),
       )
     } else if (autocompleteOptions) {
       setAutocompleteOptions([])
-- 
cgit 1.4.1

