importAlbum.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { defineStore } from "pinia";
  2. import { Song } from "@/types/song";
  3. export const useImportAlbumStore = ({ modalUuid }: { modalUuid: string }) =>
  4. defineStore(`importAlbum-${modalUuid}`, {
  5. state: (): {
  6. discogsAlbum: {
  7. album?: {
  8. albumArt: string;
  9. title: string;
  10. type: string;
  11. year: string;
  12. artists: string[];
  13. genres: string[];
  14. };
  15. dataQuality?: string;
  16. tracks?: {
  17. position: string;
  18. title: string;
  19. }[];
  20. expanded?: boolean;
  21. };
  22. originalPlaylistSongs: Song[];
  23. playlistSongs: Song[];
  24. editingSongs: boolean;
  25. discogsTab: "search" | "selected";
  26. prefillDiscogs: boolean;
  27. } => ({
  28. discogsAlbum: {},
  29. originalPlaylistSongs: [],
  30. playlistSongs: [],
  31. editingSongs: false,
  32. discogsTab: "search",
  33. prefillDiscogs: false
  34. }),
  35. actions: {
  36. showDiscogsTab(tab) {
  37. this.discogsTab = tab;
  38. },
  39. selectDiscogsAlbum(discogsAlbum) {
  40. this.discogsAlbum = JSON.parse(JSON.stringify(discogsAlbum));
  41. if (this.discogsAlbum && this.discogsAlbum.tracks) {
  42. this.tracks = this.discogsAlbum.tracks.map(track => ({
  43. ...track,
  44. songs: []
  45. }));
  46. }
  47. },
  48. toggleDiscogsAlbum() {
  49. this.discogsAlbum.expanded = !this.discogsAlbum.expanded;
  50. },
  51. setPlaylistSongs(playlistSongs) {
  52. this.originalPlaylistSongs = JSON.parse(
  53. JSON.stringify(playlistSongs)
  54. );
  55. this.playlistSongs = JSON.parse(JSON.stringify(playlistSongs));
  56. },
  57. updatePlaylistSongs(playlistSongs) {
  58. this.playlistSongs = JSON.parse(JSON.stringify(playlistSongs));
  59. },
  60. updateEditingSongs(editingSongs) {
  61. this.editingSongs = editingSongs;
  62. },
  63. resetPlaylistSongs() {
  64. this.playlistSongs = JSON.parse(
  65. JSON.stringify(this.originalPlaylistSongs)
  66. );
  67. },
  68. updatePrefillDiscogs(updatedPrefill) {
  69. this.prefillDiscogs = updatedPrefill;
  70. },
  71. updatePlaylistSong(updatedSong) {
  72. this.playlistSongs.forEach((song, index) => {
  73. if (song._id === updatedSong._id)
  74. this.playlistSongs[index] = updatedSong;
  75. });
  76. this.originalPlaylistSongs.forEach((song, index) => {
  77. if (song._id === updatedSong._id)
  78. this.originalPlaylistSongs[index] = updatedSong;
  79. });
  80. }
  81. }
  82. })();