diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-10-04 10:18:35 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-10-04 10:18:35 -0500 |
commit | 9f4b5fba4f453eda9a8c98f72fd41a2f20ed4389 (patch) | |
tree | 02f29dd3c2d5488d330937650dd7914d6e35d334 /src | |
parent | 0296e8411e528ae1c39a5d8231ba2ec89fa2633e (diff) | |
download | voidsky-9f4b5fba4f453eda9a8c98f72fd41a2f20ed4389.tar.zst |
Choose mention candidates from follows
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/modals/ComposePost.tsx | 23 |
1 files changed, 19 insertions, 4 deletions
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([]) |