From adee07cacfc2e028d9b9d3ca8e8f4024fb5b4b36 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 1 Mar 2019 20:32:03 +0300 Subject: [PATCH] Add search to users --- package.json | 1 + src/api/users.js | 7 +++++ src/store/modules/users.js | 18 +++++++++--- src/views/users/index.vue | 56 +++++++++++++++++++++----------------- yarn.lock | 9 ++++-- 5 files changed, 60 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index aef30525..7dea34b2 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "js-cookie": "2.2.0", "jsonlint": "1.6.3", "jszip": "3.1.5", + "lodash.debounce": "^4.0.8", "mockjs": "1.0.1-beta3", "normalize.css": "7.0.0", "nprogress": "0.2.0", diff --git a/src/api/users.js b/src/api/users.js index 193191ff..ed985cf0 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -14,4 +14,11 @@ export async function toggleUserActivation(nickname) { }) } +export async function searchUsers(query) { + return await request({ + url: `/api/pleroma/admin/users/search?query=${query}`, + method: 'get' + }) +} + export default { fetchUsers, toggleUserActivation } diff --git a/src/store/modules/users.js b/src/store/modules/users.js index ad95d68e..69c27f76 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -1,4 +1,4 @@ -import { fetchUsers, toggleUserActivation } from '@/api/users' +import { fetchUsers, toggleUserActivation, searchUsers } from '@/api/users' const user = { state: { @@ -7,17 +7,19 @@ const user = { }, mutations: { SET_USERS: (state, users) => { - state.fetchedUsers = users.sort((a, b) => a.id.localeCompare(b.id)) + state.fetchedUsers = users }, SET_LOADING: (state, status) => { state.loading = status }, SWAP_USER: (state, user) => { - const usersWithoutSwapped = state.fetchedUsers.filter((u) => { + const usersWithoutSwapped = state.fetchedUsers.filter(u => { return u.id !== user.id }) - state.fetchedUsers = [...usersWithoutSwapped, user].sort((a, b) => a.id.localeCompare(b.id)) + state.fetchedUsers = [...usersWithoutSwapped, user].sort((a, b) => + a.id.localeCompare(b.id) + ) }, SET_COUNT: (state, count) => { state.totalUsersCount = count @@ -39,6 +41,14 @@ const user = { const response = await toggleUserActivation(nickname) commit('SWAP_USER', response.data) + }, + async SearchUsers({ commit, dispatch }, searchValue) { + if (searchValue.length === 0) { + dispatch('FetchUsers') + } else { + const response = await searchUsers(searchValue) + commit('SET_USERS', response.data.users) + } } } } diff --git a/src/views/users/index.vue b/src/views/users/index.vue index c5feccf5..62aba6b6 100644 --- a/src/views/users/index.vue +++ b/src/views/users/index.vue @@ -1,30 +1,25 @@ - diff --git a/yarn.lock b/yarn.lock index b1bd3cb8..1353458c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5013,6 +5013,11 @@ lodash.clonedeep@^4.3.2: resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= +lodash.debounce@^4.0.8: + version "4.0.8" + resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" + integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168= + lodash.memoize@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" @@ -6906,9 +6911,9 @@ range-parser@^1.0.3, range-parser@~1.2.0: resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" integrity sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4= -"raphael@git+https://github.com/nhnent/raphael.git#2.2.0-c": +"raphael@https://github.com/nhnent/raphael.git#2.2.0-c": version "2.2.0-c" - resolved "git+https://github.com/nhnent/raphael.git#78a6ed3ec269f33b6457b0ec66f8c3d1f2ed70e0" + resolved "https://github.com/nhnent/raphael.git#78a6ed3ec269f33b6457b0ec66f8c3d1f2ed70e0" dependencies: eve "git://github.com/adobe-webplatform/eve.git#eef80ed"