importAlbum.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { defineStore } from "pinia";
  2. import { Song } from "@/types/song";
  3. export const useImportAlbumStore = props => {
  4. const { modalUuid } = props;
  5. return defineStore(`importAlbum-${modalUuid}`, {
  6. state: () => ({
  7. discogsAlbum: <
  8. {
  9. album?: {
  10. albumArt: string;
  11. title: string;
  12. type: string;
  13. year: string;
  14. artists: string[];
  15. genres: string[];
  16. };
  17. dataQuality?: string;
  18. tracks?: {
  19. position: string;
  20. title: string;
  21. }[];
  22. expanded?: boolean;
  23. }
  24. >{},
  25. originalPlaylistSongs: <Song[]>[],
  26. playlistSongs: <Song[]>[],
  27. editingSongs: false,
  28. discogsTab: "search",
  29. prefillDiscogs: false
  30. }),
  31. actions: {
  32. init({ songs }) {
  33. this.originalPlaylistSongs = JSON.parse(JSON.stringify(songs));
  34. this.playlistSongs = JSON.parse(JSON.stringify(songs));
  35. },
  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. })();
  83. };