Commit 6c885d89 authored by Mycha de Vrees's avatar Mycha de Vrees
Browse files

remove created() and let bookprovider handle results

parent 5ad32751
Pipeline #332 passed with stage
in 1 minute and 36 seconds
......@@ -24,7 +24,7 @@
<b-table striped hover borderless show-empty
id="booksTable"
ref="booksTable"
:items="bookItems"
:items="booksProvider"
:fields="bookFields"
:busy.sync="isBusy"
:filter="booksFilter"
......@@ -100,9 +100,8 @@ export default {
this.isBusy = true
await this.fetchBooks({ctx, vm: this})
// await this.$store.dispatch('fetchBooks', {ctx, vm: this})
this.isBusy = false
this.totalRows = this.$store.state.book.count
return this.$store.state.book.all
}
},
......@@ -121,12 +120,6 @@ export default {
this.currentPage = 1
this.filterDebounce(filterValue, this.filter)
}
},
created () {
this.$store.dispatch('fetchBooks', {vm: this}).then(this.$nextTick).then(() => {
this.bookItems = this.$store.state.book.all
this.totalRows = this.bookItems.length
})
}
}
</script>
......@@ -5,6 +5,7 @@
import BookTransformer from '@/transformers/BookTransformer'
import { RetrieveaBookobject_0 as getBook } from '@/api/api.js'
import CtxTransformer from '../../transformers/CtxTransformer'
// Types
export const BOOK_STATE_RESETTING = 'BOOK_STATE_RESETTING'
......@@ -31,7 +32,8 @@ const getters = {
* @returns {{all: {}, isFetching: boolean, error: string }}
*/
const getDefaultState = () => ({
all: {},
all: [],
count: 0,
isFetching: false,
error: null
})
......@@ -57,12 +59,13 @@ const actions = {
*/
async fetchBooks ({commit}, {ctx, vm}) {
try {
console.log(ctx)
commit(BOOKS_FETCHING, true, null)
const params = { contentType: 'application/json' }
const newCtx = CtxTransformer.transformCtx(ctx)
const params = { contentType: 'application/json', ...newCtx }
const response = await getBook(params)
const books = BookTransformer.fetch(response)
commit(BOOKS_FETCH_SUCCESS, books)
const { count } = response.data.meta
commit(BOOKS_FETCH_SUCCESS, { books, count })
} catch (error) {
vm.$notify({
message: error,
......@@ -85,8 +88,9 @@ const mutations = {
state.isFetching = current
state.error = error
},
[BOOKS_FETCH_SUCCESS] (state, books) {
[BOOKS_FETCH_SUCCESS] (state, { books, count }) {
state.all = books
state.count = count
state.isFetching = false
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment