diff options
| author | shpuld <shp@cock.li> | 2019-01-14 19:23:13 +0200 |
|---|---|---|
| committer | shpuld <shp@cock.li> | 2019-01-14 19:23:13 +0200 |
| commit | 17735943d5cdde1eb852d36f1c3bb699d23f7eb6 (patch) | |
| tree | d5a6b7f8d8c3512a6f262371f0038a2adb311288 /src/modules | |
| parent | a51167fa72a64505080c9aea47b5d3bc97a529b0 (diff) | |
Add media viewer module and media module component, modify attachment behavior
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/media_viewer.js | 40 |
1 files changed, 40 insertions, 0 deletions
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 |
