Compare commits

..

1 Commits

Author SHA1 Message Date
weeman bac8731e17
add pagination
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2022-01-23 20:14:52 +01:00
2 changed files with 21 additions and 5 deletions

View File

@ -42,17 +42,17 @@ export default {
state.errorMessage = errorMessage state.errorMessage = errorMessage
}, },
setQuerySearch(state, search) { setQuerySearch(state, search) {
state.query.search = search state.query = {...state.query, search}
}, },
setPages(state, pages) { setPages(state, pages) {
state.pages = pages state.pages = pages
}, },
setQueryPage(state, page) { setQueryPage(state, page) {
state.query.page = page state.query = {...state.query, page}
} }
}, },
actions: { actions: {
async search({state, commit, rootState}) { async search({state, commit, rootState, dispatch}) {
if (state.searching) { if (state.searching) {
return return
} }
@ -68,7 +68,7 @@ export default {
commit('setErrorMessage', '') commit('setErrorMessage', '')
const url = new URL(`${window.ki.apiUrl}/users/profiles`) const url = new URL(`${window.ki.apiUrl}/users/profiles`)
if (state.query.search) { if (state.query.search) {
url.searchParams.append('search', state.query.search) url.searchParams.append('search', state.query.search)
} }
@ -91,8 +91,19 @@ export default {
return return
} }
console.log(response.ok)
console.log(response.status)
console.log(state.query.page)
clearTimeout(timeoutId) clearTimeout(timeoutId)
if (!response.ok && response.status === 404 && state.query.page != 1) {
commit('setQueryPage', 1)
commit('setSearching', false)
await dispatch('search')
return
}
if (!response.ok) { if (!response.ok) {
commit('setError', true) commit('setError', true)
commit('clearProfiles') commit('clearProfiles')

View File

@ -161,11 +161,16 @@ export default {
} }
}, },
created() { created() {
if (this.$route.query.query !== undefined) { if (this.$route.query.query) {
this.searchText = this.$route.query.query this.searchText = this.$route.query.query
this.$store.commit('search/clearProfiles') this.$store.commit('search/clearProfiles')
} }
if (this.$route.query.page) {
this.currentPage = parseInt(this.$route.query.page, 10)
this.$store.commit('search/clearProfiles')
}
this.$store.dispatch('search/search') this.$store.dispatch('search/search')
} }
}; };