logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

media_viewer.js (996B)


  1. import fileTypeService from '../services/file_type/file_type.service.js'
  2. const supportedTypes = new Set(['image', 'video', 'audio', 'flash'])
  3. const mediaViewer = {
  4. state: {
  5. media: [],
  6. currentIndex: 0,
  7. activated: false
  8. },
  9. mutations: {
  10. setMedia (state, media) {
  11. state.media = media
  12. },
  13. setCurrentMedia (state, index) {
  14. state.activated = true
  15. state.currentIndex = index
  16. },
  17. close (state) {
  18. state.activated = false
  19. }
  20. },
  21. actions: {
  22. setMedia ({ commit }, attachments) {
  23. const media = attachments.filter(attachment => {
  24. const type = fileTypeService.fileType(attachment.mimetype)
  25. return supportedTypes.has(type)
  26. })
  27. commit('setMedia', media)
  28. },
  29. setCurrentMedia ({ commit, state }, current) {
  30. const index = state.media.indexOf(current)
  31. commit('setCurrentMedia', index || 0)
  32. },
  33. closeMediaViewer ({ commit }) {
  34. commit('close')
  35. }
  36. }
  37. }
  38. export default mediaViewer