FEAT: side A/B
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
import type { Box, Artist, Track } from '~/../types/types'
|
||||
import { FAVORITES_BOX_ID, useFavoritesStore } from '~/store/favorites'
|
||||
|
||||
// stores/data.ts
|
||||
import { defineStore } from 'pinia'
|
||||
import { useUiStore } from '~/store/ui'
|
||||
|
||||
export const useDataStore = defineStore('data', {
|
||||
state: () => ({
|
||||
@@ -37,7 +33,7 @@ export const useDataStore = defineStore('data', {
|
||||
artistObj = { id: 0, name: a, url: '', coverId: '' }
|
||||
} else if (a && typeof a === 'object' && 'id' in (a as any)) {
|
||||
const idVal = (a as any).id as number | undefined
|
||||
artistObj = idVal != null ? (artistMap.get(idVal) ?? (a as Artist)) : (a as Artist)
|
||||
artistObj = idVal != null ? artistMap.get(idVal) ?? (a as Artist) : (a as Artist)
|
||||
} else {
|
||||
artistObj = { id: 0, name: '', url: '', coverId: '' }
|
||||
}
|
||||
@@ -47,25 +43,17 @@ export const useDataStore = defineStore('data', {
|
||||
artist: artistObj
|
||||
}
|
||||
})
|
||||
const favBox: Box = {
|
||||
id: FAVORITES_BOX_ID,
|
||||
type: 'playlist',
|
||||
name: 'Favoris',
|
||||
duration: 0,
|
||||
tracks: [],
|
||||
description: '',
|
||||
color1: '#0f172a',
|
||||
color2: '#1e293b',
|
||||
color3: '#334155',
|
||||
state: 'box-list'
|
||||
}
|
||||
if (!this.boxes.find((b) => b.id === FAVORITES_BOX_ID)) {
|
||||
this.boxes = [...this.boxes, favBox]
|
||||
}
|
||||
this.isLoaded = true
|
||||
} finally {
|
||||
this.isLoading = false
|
||||
}
|
||||
},
|
||||
|
||||
setActiveSideByBoxId(boxId: string, side: 'A' | 'B') {
|
||||
const box = this.boxes.find((box) => box.id === boxId.replace(/[AB]$/, ''))
|
||||
if (box) {
|
||||
box.activeSide = side
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -76,15 +64,16 @@ export const useDataStore = defineStore('data', {
|
||||
return state.boxes.find((box) => box.id === id)
|
||||
}
|
||||
},
|
||||
// Obtenir toutes les pistes d'une box donnée
|
||||
getTracksByboxId: (state) => (id: string) => {
|
||||
if (id === FAVORITES_BOX_ID) {
|
||||
const fav = useFavoritesStore()
|
||||
return fav.trackIds
|
||||
.map((tid) => state.tracks.find((t) => t.id === tid))
|
||||
.filter((t): t is Track => !!t)
|
||||
getTracksByboxId: (state) => (id: string, side?: 'A' | 'B') => {
|
||||
const box = state.boxes.find((box) => box.id === id)
|
||||
if (box?.type !== 'compilation' || !side) {
|
||||
return state.tracks.filter((track) => track.boxId === id)
|
||||
}
|
||||
return state.tracks.filter((track) => track.boxId === id)
|
||||
return state.tracks.filter((track) => track.boxId === id && track.side === side)
|
||||
},
|
||||
getActiveSideByBoxId: (state) => (id: string) => {
|
||||
const box = state.boxes.find((box) => box.id === id)
|
||||
return box?.activeSide
|
||||
},
|
||||
// Filtrer les artistes selon certains critères
|
||||
getArtistById: (state) => (id: number) => state.artists.find((artist) => artist.id === id),
|
||||
@@ -101,7 +90,7 @@ export const useDataStore = defineStore('data', {
|
||||
},
|
||||
getFirstTrackOfBox() {
|
||||
return (box: Box) => {
|
||||
const tracks = this.getTracksByboxId(box.id)
|
||||
const tracks = this.getTracksByboxId(box.id, box.activeSide)
|
||||
.slice()
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
return tracks.length > 0 ? tracks[0] : null
|
||||
@@ -123,7 +112,7 @@ export const useDataStore = defineStore('data', {
|
||||
return (track: Track) => {
|
||||
// Récupérer toutes les tracks de la même box et les trier par ordre
|
||||
const tracksInBox = state.tracks
|
||||
.filter((t) => t.boxId === track.boxId)
|
||||
.filter((t) => t.boxId === track.boxId && t.side === track.side)
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
|
||||
// Trouver l’index de la track courante
|
||||
@@ -135,7 +124,7 @@ export const useDataStore = defineStore('data', {
|
||||
getPrevTrack: (state) => {
|
||||
return (track: Track) => {
|
||||
const tracksInBox = state.tracks
|
||||
.filter((t) => t.boxId === track.boxId)
|
||||
.filter((t) => t.boxId === track.boxId && t.side === track.side)
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
|
||||
const index = tracksInBox.findIndex((t) => t.id === track.id)
|
||||
|
||||
Reference in New Issue
Block a user