Move media_viewer module to store
This commit is contained in:
parent
3430604dda
commit
c25cfe540b
8 changed files with 49 additions and 56 deletions
30
src/stores/media_viewer.js
Normal file
30
src/stores/media_viewer.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import fileTypeService from '../services/file_type/file_type.service.js'
|
||||
|
||||
const supportedTypes = new Set(['image', 'video', 'audio', 'flash'])
|
||||
|
||||
export const useMediaViewerStore = defineStore('mediaViewer', {
|
||||
state: () => ({
|
||||
media: [],
|
||||
currentIndex: 0,
|
||||
activated: false
|
||||
}),
|
||||
actions: {
|
||||
setMedia (attachments) {
|
||||
const media = attachments.filter(attachment => {
|
||||
const type = fileTypeService.fileType(attachment.mimetype)
|
||||
return supportedTypes.has(type)
|
||||
})
|
||||
|
||||
this.media = media
|
||||
},
|
||||
setCurrentMedia (current) {
|
||||
const index = this.media.indexOf(current)
|
||||
this.activated = true
|
||||
this.currentIndex = index
|
||||
},
|
||||
closeMediaViewer () {
|
||||
this.activated = false
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue