Add pagination to users

This commit is contained in:
Maxim Filippov 2019-02-28 01:13:20 +03:00
parent a90cdd1cac
commit a2a69e509c
3 changed files with 35 additions and 5 deletions

View file

@ -1,8 +1,8 @@
import request from '@/utils/request' import request from '@/utils/request'
export async function fetchUsers() { export async function fetchUsers(page = 1) {
return await request({ return await request({
url: '/api/pleroma/admin/users', url: `/api/pleroma/admin/users?page=${page}`,
method: 'get' method: 'get'
}) })
} }

View file

@ -18,13 +18,21 @@ const user = {
}) })
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
},
SET_PAGE_SIZE: (state, pageSize) => {
state.pageSize = pageSize
} }
}, },
actions: { actions: {
async FetchUsers({ commit }) { async FetchUsers({ commit }, page = 1) {
const response = await fetchUsers() const response = await fetchUsers(page)
commit('SET_USERS', response.data) commit('SET_USERS', response.data.users)
commit('SET_COUNT', response.data.count)
commit('SET_PAGE_SIZE', response.data.page_size)
commit('SET_LOADING', false) commit('SET_LOADING', false)
}, },
async ToggleUserActivation({ commit }, nickname) { async ToggleUserActivation({ commit }, nickname) {

View file

@ -29,6 +29,14 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<div v-if="!loading" class="pagination">
<el-pagination
:total="usersCount"
:page-size="pageSize"
background
layout="prev, pager, next"
@current-change="handlePageChange" />
</div>
</div> </div>
</template> </template>
@ -42,6 +50,12 @@ export default {
}, },
users() { users() {
return this.$store.state.users.fetchedUsers return this.$store.state.users.fetchedUsers
},
usersCount() {
return this.$store.state.users.totalUsersCount
},
pageSize() {
return this.$store.state.users.pageSize
} }
}, },
mounted: function() { mounted: function() {
@ -50,6 +64,9 @@ export default {
methods: { methods: {
handleDeactivate({ nickname }) { handleDeactivate({ nickname }) {
this.$store.dispatch('ToggleUserActivation', nickname) this.$store.dispatch('ToggleUserActivation', nickname)
},
handlePageChange(page) {
this.$store.dispatch('FetchUsers', page)
} }
} }
} }
@ -62,6 +79,11 @@ export default {
h1 { h1 {
margin-left: 15px; margin-left: 15px;
} }
.pagination {
margin: 25px 0 0;
text-align: center;
}
} }
</style> </style>