editSong.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. new Promise(resolve => {
  27. commit("getCurrentTime", fixedVal);
  28. resolve(state.video.currentTime);
  29. }),
  30. updateSongField: ({ commit }, data) => commit("updateSongField", data),
  31. selectDiscogsInfo: ({ commit }, discogsInfo) =>
  32. commit("selectDiscogsInfo", discogsInfo),
  33. updateReports: ({ commit }, reports) =>
  34. commit("updateReports", reports),
  35. resolveReport: ({ commit }, reportId) =>
  36. commit("resolveReport", reportId),
  37. updateYoutubeId: ({ commit }, youtubeId) => {
  38. commit("updateYoutubeId", youtubeId);
  39. commit("loadVideoById", youtubeId, 0);
  40. }
  41. },
  42. mutations: {
  43. showTab(state, tab) {
  44. state.tab = tab;
  45. },
  46. editSong(state, song) {
  47. if (song.discogs === undefined) song.discogs = null;
  48. state.originalSong = JSON.parse(JSON.stringify(song));
  49. state.song = { ...song };
  50. },
  51. stopVideo(state) {
  52. state.video.player.stopVideo();
  53. },
  54. loadVideoById(state, id, skipDuration) {
  55. state.song.duration = -1;
  56. state.video.player.loadVideoById(id, skipDuration);
  57. },
  58. pauseVideo(state, status) {
  59. if (status) state.video.player.pauseVideo();
  60. else state.video.player.playVideo();
  61. state.video.paused = status;
  62. },
  63. getCurrentTime(state, fixedVal) {
  64. if (!state.playerReady) state.video.currentTime = 0;
  65. else {
  66. Promise.resolve(state.video.player.getCurrentTime()).then(
  67. time => {
  68. if (fixedVal)
  69. Promise.resolve(time.toFixed(fixedVal)).then(
  70. fixedTime => {
  71. state.video.currentTime = fixedTime;
  72. }
  73. );
  74. else state.video.currentTime = time;
  75. }
  76. );
  77. }
  78. },
  79. updateSongField(state, data) {
  80. state.song[data.field] = data.value;
  81. },
  82. selectDiscogsInfo(state, discogsInfo) {
  83. state.song.discogs = discogsInfo;
  84. },
  85. updateReports(state, reports) {
  86. state.reports = reports;
  87. },
  88. resolveReport(state, reportId) {
  89. state.reports = state.reports.filter(
  90. report => report._id !== reportId
  91. );
  92. },
  93. updateYoutubeId(state, youtubeId) {
  94. state.song.youtubeId = youtubeId;
  95. }
  96. }
  97. };