2019-01-14 17:23:13 +00:00
|
|
|
import fileTypeService from '../services/file_type/file_type.service.js'
|
2021-06-17 23:01:37 +00:00
|
|
|
const supportedTypes = new Set(['image', 'video', 'audio', 'flash'])
|
2019-01-14 17:23:13 +00:00
|
|
|
|
|
|
|
const mediaViewer = {
|
|
|
|
state: {
|
|
|
|
media: [],
|
|
|
|
currentIndex: 0,
|
|
|
|
activated: false
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
setMedia (state, media) {
|
|
|
|
state.media = media
|
|
|
|
},
|
2021-06-17 23:01:37 +00:00
|
|
|
setCurrentMedia (state, index) {
|
2019-01-14 17:23:13 +00:00
|
|
|
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)
|
2021-06-17 23:01:37 +00:00
|
|
|
return supportedTypes.has(type)
|
2019-01-14 17:23:13 +00:00
|
|
|
})
|
|
|
|
commit('setMedia', media)
|
|
|
|
},
|
2021-06-17 23:01:37 +00:00
|
|
|
setCurrentMedia ({ commit, state }, current) {
|
2019-01-14 17:23:13 +00:00
|
|
|
const index = state.media.indexOf(current)
|
2021-06-17 23:01:37 +00:00
|
|
|
commit('setCurrentMedia', index || 0)
|
2019-01-14 17:23:13 +00:00
|
|
|
},
|
|
|
|
closeMediaViewer ({ commit }) {
|
|
|
|
commit('close')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default mediaViewer
|