Commit 6678349f authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

move file listing and show selector to own components

parent 9296781e
This diff is collapsed.
...@@ -27,6 +27,7 @@ import { mapGetters } from 'vuex' ...@@ -27,6 +27,7 @@ import { mapGetters } from 'vuex'
export default { export default {
props: { props: {
title: { type: String, default: 'Unlabeled component title' }, title: { type: String, default: 'Unlabeled component title' },
callback: { type: Function, default: null }
}, },
computed: { computed: {
...@@ -45,6 +46,7 @@ export default { ...@@ -45,6 +46,7 @@ export default {
methods: { methods: {
switchShow: function (index) { switchShow: function (index) {
this.$store.commit('shows/switchShow', index) this.$store.commit('shows/switchShow', index)
if (this.callback) { this.callback() }
}, },
} }
} }
......
This diff is collapsed.
import axios from 'axios'
import handleApiError from '../handleApiError'
const state = { const state = {
items: [], files: [],
loaded: {
files: false,
}
} }
const getters = { const getters = {
items: state => state.items, files: state => state.files,
itemCount: state => state.items.length, fileCount: state => state.files.length,
} }
const actions = { const mutations = {
addItem ({commit}, item) { loading(state, item) { state.loaded[item] = false },
commit('addItem', item) finishLoading(state, item) { state.loaded[item] = true },
}
setFiles (state, files) { state.files = files },
addFile (state, file) { state.files.push(file) },
} }
const mutations = { const actions = {
addItem (state, item) { // Fetch all files for a given show from the AuRa tank API
state.items.push(item) fetchFiles (ctx, data) {
} ctx.commit('loading', 'files')
let uri = process.env.VUE_APP_API_TANK + 'shows/' + data.slug + '/files'
axios.get(uri, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + ctx.rootState.auth.user.access_token }
}).then(response => {
// we don't have to check separately, if there are files, because tank
// always provides an empty array if there are no files (or even if there is no corresponding show)
ctx.commit('setFiles', response.data.results)
ctx.commit('finishLoading', 'files')
if (data && typeof(data.callback) === 'function') { data.callback() }
}).catch(error => {
handleApiError(this, error, 'could not load shows')
if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel() }
})
},
} }
export default { export default {
......
Markdown is supported
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