importAlbum.ts 2.2 KB

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