logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe
commit: 029dc7405ec5bb7a99724d6307d0316d5d0cb8c2
parent: cc2e35f4999a16a6647887f1c4f09e2b19a54b3e
Author: Shpuld Shpludson <shp@cock.li>
Date:   Thu, 18 Jul 2019 03:40:02 +0000

Merge branch 'add-user-search-at' into 'develop'

Add user search at

See merge request pleroma/pleroma-fe!852

Diffstat:

Msrc/components/emoji-input/suggestor.js21++++++++++++++++++---
Msrc/components/post_status_form/post_status_form.js3++-
Msrc/components/user_settings/user_settings.js3++-
3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/components/emoji-input/suggestor.js b/src/components/emoji-input/suggestor.js @@ -1,20 +1,27 @@ +import { debounce } from 'lodash' /** * suggest - generates a suggestor function to be used by emoji-input * data: object providing source information for specific types of suggestions: * data.emoji - optional, an array of all emoji available i.e. * (state.instance.emoji + state.instance.customEmoji) * data.users - optional, an array of all known users + * updateUsersList - optional, a function to search and append to users * * Depending on data present one or both (or none) can be present, so if field * doesn't support user linking you can just provide only emoji. */ + +const debounceUserSearch = debounce((data, input) => { + data.updateUsersList(input) +}, 500, {leading: true, trailing: false}) + export default data => input => { const firstChar = input[0] if (firstChar === ':' && data.emoji) { return suggestEmoji(data.emoji)(input) } if (firstChar === '@' && data.users) { - return suggestUsers(data.users)(input) + return suggestUsers(data)(input) } return [] } @@ -38,9 +45,11 @@ export const suggestEmoji = emojis => input => { }) } -export const suggestUsers = users => input => { +export const suggestUsers = data => input => { const noPrefix = input.toLowerCase().substr(1) - return users.filter( + const users = data.users + + const newUsers = users.filter( user => user.screen_name.toLowerCase().startsWith(noPrefix) || user.name.toLowerCase().startsWith(noPrefix) @@ -75,5 +84,11 @@ export const suggestUsers = users => input => { imageUrl: profile_image_url_original, replacement: '@' + screen_name + ' ' })) + + // BE search users if there are no matches + if (newUsers.length === 0 && data.updateUsersList) { + debounceUserSearch(data, noPrefix) + } + return newUsers /* eslint-enable camelcase */ } diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js @@ -104,7 +104,8 @@ const PostStatusForm = { ...this.$store.state.instance.emoji, ...this.$store.state.instance.customEmoji ], - users: this.$store.state.users.users + users: this.$store.state.users.users, + updateUsersList: (input) => this.$store.dispatch('searchUsers', input) }) }, emojiSuggestor () { diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js @@ -91,7 +91,8 @@ const UserSettings = { ...this.$store.state.instance.emoji, ...this.$store.state.instance.customEmoji ], - users: this.$store.state.users.users + users: this.$store.state.users.users, + updateUsersList: (input) => this.$store.dispatch('searchUsers', input) }) }, emojiSuggestor () {