2019-01-14 09:23:13 -08:00
|
|
|
import fileTypeService from '../services/file_type/file_type.service.js'
|
|
|
|
|
|
|
|
const mediaViewer = {
|
|
|
|
state: {
|
|
|
|
media: [],
|
|
|
|
currentIndex: 0,
|
|
|
|
activated: false
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
setMedia (state, media) {
|
|
|
|
state.media = media
|
|
|
|
},
|
|
|
|
setCurrent (state, index) {
|
|
|
|
state.activated = true
|
|
|
|
state.currentIndex = index
|
|
|
|
},
|
|
|
|
close (state) {
|
|
|
|
state.activated = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setMedia ({ commit }, attachments) {
|
|
|
|
const media = attachments.filter(attachment => {
|
|
|
|
const type = fileTypeService.fileType(attachment.mimetype)
|
2020-06-29 04:48:22 -07:00
|
|
|
return type === 'image' || type === 'video' || type === 'audio'
|
2019-01-14 09:23:13 -08:00
|
|
|
})
|
|
|
|
commit('setMedia', media)
|
|
|
|
},
|
|
|
|
setCurrent ({ commit, state }, current) {
|
|
|
|
const index = state.media.indexOf(current)
|
|
|
|
commit('setCurrent', index || 0)
|
|
|
|
},
|
|
|
|
closeMediaViewer ({ commit }) {
|
|
|
|
commit('close')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default mediaViewer
|