Implemented local users filtration in fetch and search requests

This commit is contained in:
Angelina Filippova 2019-03-05 02:40:42 +03:00
parent de13254f0a
commit 7652bfcd58
2 changed files with 11 additions and 24 deletions

View file

@ -1,8 +1,8 @@
import request from '@/utils/request'
export async function fetchUsers(page = 1) {
export async function fetchUsers(page = 1, showLocalUsers) {
return await request({
url: `/api/pleroma/admin/users?page=${page}`,
url: `/api/pleroma/admin/users?page=${page}&local_only=${showLocalUsers}`,
method: 'get'
})
}
@ -14,16 +14,9 @@ export async function toggleUserActivation(nickname) {
})
}
export async function searchUsers(query, page = 1) {
export async function searchUsers(query, page = 1, showLocalUsers) {
return await request({
url: `/api/pleroma/admin/users?query=${query}&page=${page}`,
method: 'get'
})
}
export async function fetchLocalUsers(page = 1) {
return await request({
url: `/api/pleroma/admin/users?page=${page}&local_only=true`,
url: `/api/pleroma/admin/users?query=${query}&page=${page}&local_only=${showLocalUsers}`,
method: 'get'
})
}

View file

@ -1,4 +1,4 @@
import { fetchUsers, toggleUserActivation, searchUsers, fetchLocalUsers } from '@/api/users'
import { fetchUsers, toggleUserActivation, searchUsers } from '@/api/users'
const user = {
state: {
@ -42,8 +42,8 @@ const user = {
}
},
actions: {
async FetchUsers({ commit }, { page }) {
const response = await fetchUsers(page)
async FetchUsers({ commit, state }, { page }) {
const response = await fetchUsers(page, state.showLocalUsers)
commit('SET_LOADING', true)
@ -54,7 +54,7 @@ const user = {
commit('SWAP_USER', response.data)
},
async SearchUsers({ commit, dispatch }, { query, page }) {
async SearchUsers({ commit, dispatch, state }, { query, page }) {
if (query.length === 0) {
commit('SET_SEARCH_QUERY', query)
dispatch('FetchUsers', page)
@ -62,20 +62,14 @@ const user = {
commit('SET_LOADING', true)
commit('SET_SEARCH_QUERY', query)
const response = await searchUsers(query, page)
const response = await searchUsers(query, page, state.showLocalUsers)
loadUsers(commit, page, response.data)
}
},
async ToggleLocalUsersFilter({ commit, dispatch }, value) {
async ToggleLocalUsersFilter({ commit, dispatch, state }, value) {
commit('SET_LOCAL_USERS_FILTER', value)
if (value) {
const response = await fetchLocalUsers()
loadUsers(commit, 1, response.data)
} else {
dispatch('FetchUsers', 1)
}
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
}
}
}