From d05bd31092cc41f45314a50eb71e0eb0ed6bafbe Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 1 Apr 2019 15:34:18 -0400 Subject: [PATCH 01/20] setup vue-autosuggest --- package.json | 1 + yarn.lock | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index c80e0f63..6b7a368e 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "sanitize-html": "^1.13.0", "sass-loader": "^4.0.2", "vue": "^2.5.13", + "vue-autosuggest": "^1.8.3", "vue-chat-scroll": "^1.2.1", "vue-compose": "^0.7.1", "vue-i18n": "^7.3.2", diff --git a/yarn.lock b/yarn.lock index 58007622..1f8caca1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6422,6 +6422,10 @@ void-elements@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" +vue-autosuggest@^1.8.3: + version "1.8.3" + resolved "https://registry.yarnpkg.com/vue-autosuggest/-/vue-autosuggest-1.8.3.tgz#dcce3d3ed90441c9788b6d18b2e67e5b9d4cad52" + vue-chat-scroll@^1.2.1: version "1.3.5" resolved "https://registry.yarnpkg.com/vue-chat-scroll/-/vue-chat-scroll-1.3.5.tgz#a5ee5bae5058f614818a96eac5ee3be4394a2f68" From da5844205c5e2ead4da42f89f1f9586683af693e Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 06:12:31 -0400 Subject: [PATCH 02/20] add user autosuggest component --- .../user_autosuggest/user_autosuggest.js | 41 ++++++++ .../user_autosuggest/user_autosuggest.vue | 93 +++++++++++++++++++ src/components/user_settings/user_settings.js | 4 +- .../user_settings/user_settings.vue | 3 +- 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 src/components/user_autosuggest/user_autosuggest.js create mode 100644 src/components/user_autosuggest/user_autosuggest.vue diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js new file mode 100644 index 00000000..6612c2f3 --- /dev/null +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -0,0 +1,41 @@ +import { VueAutosuggest } from 'vue-autosuggest' +import BasicUserCard from '../basic_user_card/basic_user_card.vue' +import userSearchApi from '../../services/new_api/user_search.js' + +export default { + components: { + VueAutosuggest, + BasicUserCard + }, + data () { + return { + results: [], + timeout: null, + selected: null, + debounceMilliseconds: 500, + inputProps: { + id: 'autosuggest__input', + onInputChange: this.fetchResults, + placeholder: 'Search...', + class: 'form-control' + }, + suggestions: [] + } + }, + methods: { + fetchResults (query) { + clearTimeout(this.timeout) + this.timeout = setTimeout(() => { + userSearchApi.search({query, store: this.$store}) + .then((data) => { this.suggestions = [{ data }] }) + }, this.debounceMilliseconds) + }, + clickHandler (item) { + return false + }, + clickUserHandler () { + console.log('clickUserHandler') + return false + } + } +} diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue new file mode 100644 index 00000000..48fe350d --- /dev/null +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -0,0 +1,93 @@ + + + + + diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index b6a0479d..d5772082 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -9,6 +9,7 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for import BlockCard from '../block_card/block_card.vue' import MuteCard from '../mute_card/mute_card.vue' import EmojiInput from '../emoji-input/emoji-input.vue' +import UserAutoSuggest from '../user_autosuggest/user_autosuggest.vue' import withSubscription from '../../hocs/with_subscription/with_subscription' import withList from '../../hocs/with_list/with_list' @@ -73,7 +74,8 @@ const UserSettings = { ImageCropper, BlockList, MuteList, - EmojiInput + EmojiInput, + UserAutoSuggest }, computed: { user () { diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index c08698dc..d98a8eba 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -22,7 +22,7 @@

{{$t('settings.name_bio')}}

{{$t('settings.name')}}

-
+ From 94e67ff11894c13bf34f1b31802a1497caa03897 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 12:31:45 -0400 Subject: [PATCH 03/20] rewrite USerAutoSuggest without any dependency --- .../user_autosuggest/user_autosuggest.js | 37 +++----- .../user_autosuggest/user_autosuggest.vue | 94 +++---------------- 2 files changed, 29 insertions(+), 102 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index 6612c2f3..eff6ef75 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -1,41 +1,34 @@ -import { VueAutosuggest } from 'vue-autosuggest' import BasicUserCard from '../basic_user_card/basic_user_card.vue' import userSearchApi from '../../services/new_api/user_search.js' +const debounceMilliseconds = 500 + export default { components: { - VueAutosuggest, BasicUserCard }, data () { return { + query: '', results: [], - timeout: null, - selected: null, - debounceMilliseconds: 500, - inputProps: { - id: 'autosuggest__input', - onInputChange: this.fetchResults, - placeholder: 'Search...', - class: 'form-control' - }, - suggestions: [] + timeout: null + } + }, + watch: { + query (val) { + this.fetchResults(val) } }, methods: { fetchResults (query) { clearTimeout(this.timeout) this.timeout = setTimeout(() => { - userSearchApi.search({query, store: this.$store}) - .then((data) => { this.suggestions = [{ data }] }) - }, this.debounceMilliseconds) - }, - clickHandler (item) { - return false - }, - clickUserHandler () { - console.log('clickUserHandler') - return false + this.results = [] + if (query) { + userSearchApi.search({query, store: this.$store}) + .then((data) => { this.results = data }) + } + }, debounceMilliseconds) } } } diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index 48fe350d..04e38a60 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,93 +1,27 @@ From b2eb43e3c8d49fcd43c3d864d7cc50dff9c5e3ff Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 12:33:01 -0400 Subject: [PATCH 04/20] rename css classes --- src/components/user_autosuggest/user_autosuggest.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index 04e38a60..743d9eaf 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,7 +1,7 @@ diff --git a/src/modules/users.js b/src/modules/users.js index 6de50b80..545b1d58 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -281,6 +281,9 @@ const users = { unregisterPushNotifications(token) }, + addNewUsers ({ commit }, users) { + commit('addNewUsers', users) + }, addNewStatuses (store, { statuses }) { const users = map(statuses, 'user') const retweetedUsers = compact(map(statuses, 'retweeted_status.user')) From 60b07eeaa44bcfa99e90aa075cd18086d25ef194 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 14:01:21 -0400 Subject: [PATCH 09/20] filter out blocked user or me from the results --- src/components/user_autosuggest/user_autosuggest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index 42914b36..c8332e34 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -1,3 +1,4 @@ +import reject from 'lodash/reject' import BlockCard from '../block_card/block_card.vue' import userSearchApi from '../../services/new_api/user_search.js' @@ -27,9 +28,12 @@ export default { this.results = [] if (query) { userSearchApi.search({query, store: this.$store}) - .then((data) => { - this.$store.dispatch('addNewUsers', data) - this.results = data + .then((users) => { + const filteredUsers = reject(users, (user) => { + return user.statusnet_blocking || user.id === this.$store.state.users.currentUser.id + }) + this.$store.dispatch('addNewUsers', filteredUsers) + this.results = filteredUsers this.resultsVisible = true }) } From 33467880edc80f2bce205b8d426a65a751b9baf2 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 14:07:03 -0400 Subject: [PATCH 10/20] improve ui --- src/components/user_autosuggest/user_autosuggest.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index d85fabf1..6253ca6b 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,7 +1,7 @@