pleroma-fe/src/stores/media_viewer.js

31 lines
789 B
JavaScript
Raw Normal View History

2023-04-05 13:55:38 -06:00
import { defineStore } from 'pinia'
2026-01-08 17:26:52 +02:00
2023-04-05 13:55:38 -06:00
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,
2026-01-06 16:22:52 +02:00
activated: false,
2023-04-05 13:55:38 -06:00
}),
actions: {
2026-01-06 16:22:52 +02:00
setMedia(attachments) {
const media = attachments.filter((attachment) => {
2023-04-05 13:55:38 -06:00
const type = fileTypeService.fileType(attachment.mimetype)
return supportedTypes.has(type)
})
this.media = media
},
2026-01-06 16:22:52 +02:00
setCurrentMedia(current) {
2023-04-05 13:55:38 -06:00
const index = this.media.indexOf(current)
this.activated = true
this.currentIndex = index
},
2026-01-06 16:22:52 +02:00
closeMediaViewer() {
2023-04-05 13:55:38 -06:00
this.activated = false
2026-01-06 16:22:52 +02:00
},
},
2023-04-05 13:55:38 -06:00
})