importAlbum.ts 2.2 KB

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