editSong.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* eslint no-param-reassign: 0 */
  2. export default {
  3. namespaced: true,
  4. state: {
  5. video: {
  6. player: null,
  7. paused: true,
  8. playerReady: false,
  9. autoPlayed: false,
  10. currentTime: 0
  11. },
  12. song: {},
  13. originalSong: {},
  14. reports: [],
  15. tab: "discogs"
  16. },
  17. getters: {},
  18. actions: {
  19. showTab: ({ commit }, tab) => commit("showTab", tab),
  20. editSong: ({ commit }, song) => commit("editSong", song),
  21. stopVideo: ({ commit }) => commit("stopVideo"),
  22. loadVideoById: ({ commit }, id, skipDuration) =>
  23. commit("loadVideoById", id, skipDuration),
  24. pauseVideo: ({ commit }, status) => commit("pauseVideo", status),
  25. getCurrentTime: ({ commit, state }, fixedVal) => {
  26. return new Promise(resolve => {
  27. commit("getCurrentTime", fixedVal);
  28. resolve(state.video.currentTime);
  29. });
  30. },
  31. updateSongField: ({ commit }, data) => commit("updateSongField", data),
  32. selectDiscogsInfo: ({ commit }, discogsInfo) =>
  33. commit("selectDiscogsInfo", discogsInfo),
  34. updateReports: ({ commit }, reports) =>
  35. commit("updateReports", reports),
  36. resolveReport: ({ commit }, reportId) =>
  37. commit("resolveReport", reportId)
  38. },
  39. mutations: {
  40. showTab(state, tab) {
  41. state.tab = tab;
  42. },
  43. editSong(state, song) {
  44. if (song.discogs === undefined) song.discogs = null;
  45. state.originalSong = JSON.parse(JSON.stringify(song));
  46. state.song = { ...song };
  47. },
  48. stopVideo(state) {
  49. state.video.player.stopVideo();
  50. },
  51. loadVideoById(state, id, skipDuration) {
  52. state.video.player.loadVideoById(id, skipDuration);
  53. },
  54. pauseVideo(state, status) {
  55. if (status) state.video.player.pauseVideo();
  56. else state.video.player.playVideo();
  57. state.video.paused = status;
  58. },
  59. getCurrentTime(state, fixedVal) {
  60. if (!state.playerReady) state.video.currentTime = 0;
  61. else {
  62. Promise.resolve(state.video.player.getCurrentTime()).then(
  63. time => {
  64. if (fixedVal)
  65. Promise.resolve(time.toFixed(fixedVal)).then(
  66. fixedTime => {
  67. state.video.currentTime = fixedTime;
  68. }
  69. );
  70. else state.video.currentTime = time;
  71. }
  72. );
  73. }
  74. },
  75. updateSongField(state, data) {
  76. state.song[data.field] = data.value;
  77. },
  78. selectDiscogsInfo(state, discogsInfo) {
  79. state.song.discogs = discogsInfo;
  80. },
  81. updateReports(state, reports) {
  82. state.reports = reports;
  83. },
  84. resolveReport(state, reportId) {
  85. state.reports = state.reports.filter(
  86. report => report._id !== reportId
  87. );
  88. }
  89. }
  90. };