From 17735943d5cdde1eb852d36f1c3bb699d23f7eb6 Mon Sep 17 00:00:00 2001 From: shpuld Date: Mon, 14 Jan 2019 19:23:13 +0200 Subject: Add media viewer module and media module component, modify attachment behavior --- src/modules/media_viewer.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/modules/media_viewer.js (limited to 'src/modules/media_viewer.js') diff --git a/src/modules/media_viewer.js b/src/modules/media_viewer.js new file mode 100644 index 00000000..27714bae --- /dev/null +++ b/src/modules/media_viewer.js @@ -0,0 +1,40 @@ +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) + return type === 'image' || type === 'video' + }) + commit('setMedia', media) + }, + setCurrent ({ commit, state }, current) { + const index = state.media.indexOf(current) + console.log(index, current) + commit('setCurrent', index || 0) + }, + closeMediaViewer ({ commit }) { + commit('close') + } + } +} + +export default mediaViewer -- cgit v1.2.3-70-g09d2