editSong.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. songId: "",
  13. song: {},
  14. originalSong: {},
  15. reports: [],
  16. tab: "discogs"
  17. },
  18. getters: {},
  19. actions: {
  20. showTab: ({ commit }, tab) => commit("showTab", tab),
  21. editSong: ({ commit }, song) => commit("editSong", song),
  22. setSong: ({ commit }, song) => commit("setSong", song),
  23. resetSong: ({ commit }, songId) => commit("resetSong", songId),
  24. stopVideo: ({ commit }) => commit("stopVideo"),
  25. loadVideoById: ({ commit }, id, skipDuration) =>
  26. commit("loadVideoById", id, skipDuration),
  27. pauseVideo: ({ commit }, status) => commit("pauseVideo", status),
  28. getCurrentTime: ({ commit, state }, fixedVal) =>
  29. new Promise(resolve => {
  30. commit("getCurrentTime", fixedVal);
  31. resolve(state.video.currentTime);
  32. }),
  33. updateSongField: ({ commit }, data) => commit("updateSongField", data),
  34. selectDiscogsInfo: ({ commit }, discogsInfo) =>
  35. commit("selectDiscogsInfo", discogsInfo),
  36. updateReports: ({ commit }, reports) =>
  37. commit("updateReports", reports),
  38. resolveReport: ({ commit }, reportId) =>
  39. commit("resolveReport", reportId),
  40. updateYoutubeId: ({ commit }, youtubeId) => {
  41. commit("updateYoutubeId", youtubeId);
  42. commit("loadVideoById", youtubeId, 0);
  43. }
  44. },
  45. mutations: {
  46. showTab(state, tab) {
  47. state.tab = tab;
  48. },
  49. editSong(state, song) {
  50. state.songId = song.songId;
  51. state.prefillData = song.prefill ? song.prefill : {};
  52. },
  53. setSong(state, song) {
  54. if (song.discogs === undefined) song.discogs = null;
  55. state.originalSong = JSON.parse(JSON.stringify(song));
  56. state.song = { ...song };
  57. },
  58. resetSong(state, songId) {
  59. state.originalSong = {};
  60. state.song = {};
  61. if (state.songId === songId) this.songId = "";
  62. // if (state.originalSong._id === songId) state.originalSong = {};
  63. // if (state.song._id === songId) state.song = {};
  64. // if (state.songId === songId) this.songId = "";
  65. },
  66. stopVideo(state) {
  67. state.video.player.stopVideo();
  68. },
  69. loadVideoById(state, id, skipDuration) {
  70. state.song.duration = -1;
  71. state.video.player.loadVideoById(id, skipDuration);
  72. },
  73. pauseVideo(state, status) {
  74. if (status) state.video.player.pauseVideo();
  75. else state.video.player.playVideo();
  76. state.video.paused = status;
  77. },
  78. getCurrentTime(state, fixedVal) {
  79. if (!state.playerReady) state.video.currentTime = 0;
  80. else {
  81. Promise.resolve(state.video.player.getCurrentTime()).then(
  82. time => {
  83. if (fixedVal)
  84. Promise.resolve(time.toFixed(fixedVal)).then(
  85. fixedTime => {
  86. state.video.currentTime = fixedTime;
  87. }
  88. );
  89. else state.video.currentTime = time;
  90. }
  91. );
  92. }
  93. },
  94. updateSongField(state, data) {
  95. state.song[data.field] = data.value;
  96. },
  97. selectDiscogsInfo(state, discogsInfo) {
  98. state.song.discogs = discogsInfo;
  99. },
  100. updateReports(state, reports) {
  101. state.reports = reports;
  102. },
  103. resolveReport(state, reportId) {
  104. state.reports = state.reports.filter(
  105. report => report._id !== reportId
  106. );
  107. },
  108. updateYoutubeId(state, youtubeId) {
  109. state.song.youtubeId = youtubeId;
  110. }
  111. }
  112. };