pleroma-fe/src/stores/media_viewer.js
2026-01-08 17:42:20 +02:00

31 lines
789 B
JavaScript

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
},
},
})