1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { defineStore } from "pinia";
- import { Song } from "@/types/song";
- export const useImportAlbumStore = ({ modalUuid }: { modalUuid: string }) =>
- defineStore(`importAlbum-${modalUuid}`, {
- state: (): {
- discogsAlbum: {
- album?: {
- albumArt: string;
- title: string;
- type: string;
- year: string;
- artists: string[];
- genres: string[];
- };
- dataQuality?: string;
- tracks?: {
- position: string;
- title: string;
- }[];
- expanded?: boolean;
- };
- originalPlaylistSongs: Song[];
- playlistSongs: Song[];
- editingSongs: boolean;
- discogsTab: "search" | "selected";
- prefillDiscogs: boolean;
- } => ({
- discogsAlbum: {},
- originalPlaylistSongs: [],
- playlistSongs: [],
- editingSongs: false,
- discogsTab: "search",
- prefillDiscogs: false
- }),
- actions: {
- showDiscogsTab(tab) {
- this.discogsTab = tab;
- },
- selectDiscogsAlbum(discogsAlbum) {
- this.discogsAlbum = JSON.parse(JSON.stringify(discogsAlbum));
- if (this.discogsAlbum && this.discogsAlbum.tracks) {
- this.tracks = this.discogsAlbum.tracks.map(track => ({
- ...track,
- songs: []
- }));
- }
- },
- toggleDiscogsAlbum() {
- this.discogsAlbum.expanded = !this.discogsAlbum.expanded;
- },
- setPlaylistSongs(playlistSongs) {
- this.originalPlaylistSongs = JSON.parse(
- JSON.stringify(playlistSongs)
- );
- this.playlistSongs = JSON.parse(JSON.stringify(playlistSongs));
- },
- updatePlaylistSongs(playlistSongs) {
- this.playlistSongs = JSON.parse(JSON.stringify(playlistSongs));
- },
- updateEditingSongs(editingSongs) {
- this.editingSongs = editingSongs;
- },
- resetPlaylistSongs() {
- this.playlistSongs = JSON.parse(
- JSON.stringify(this.originalPlaylistSongs)
- );
- },
- updatePrefillDiscogs(updatedPrefill) {
- this.prefillDiscogs = updatedPrefill;
- },
- updatePlaylistSong(updatedSong) {
- this.playlistSongs.forEach((song, index) => {
- if (song._id === updatedSong._id)
- this.playlistSongs[index] = updatedSong;
- });
- this.originalPlaylistSongs.forEach((song, index) => {
- if (song._id === updatedSong._id)
- this.originalPlaylistSongs[index] = updatedSong;
- });
- }
- }
- })();
|