editPlaylist.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { defineStore } from "pinia";
  2. export const useEditPlaylistStore = props => {
  3. const { modalUuid } = props;
  4. if (!modalUuid || modalUuid === "") return false;
  5. return defineStore(`editPlaylist-${modalUuid}`, {
  6. state: () => ({
  7. playlistId: null,
  8. tab: "settings",
  9. playlist: { songs: [] }
  10. }),
  11. actions: {
  12. init({ playlistId }) {
  13. this.playlistId = playlistId;
  14. },
  15. showTab(tab) {
  16. this.tab = tab;
  17. },
  18. setPlaylist(playlist) {
  19. this.playlist = { ...playlist };
  20. this.playlist.songs.sort((a, b) => a.position - b.position);
  21. },
  22. clearPlaylist() {
  23. this.playlist = { songs: [] };
  24. },
  25. addSong(song) {
  26. this.playlist.songs.push(song);
  27. },
  28. removeSong(youtubeId) {
  29. this.playlist.songs = this.playlist.songs.filter(
  30. song => song.youtubeId !== youtubeId
  31. );
  32. },
  33. updatePlaylistSongs(playlistSongs) {
  34. this.playlist.songs = playlistSongs;
  35. },
  36. repositionedSong(song) {
  37. if (
  38. this.playlist.songs[song.newIndex] &&
  39. this.playlist.songs[song.newIndex].youtubeId ===
  40. song.youtubeId
  41. )
  42. return;
  43. this.playlist.songs.splice(
  44. song.newIndex,
  45. 0,
  46. this.playlist.songs.splice(song.oldIndex, 1)[0]
  47. );
  48. }
  49. }
  50. })();
  51. };