[web] Remove the lyrics store

This commit is contained in:
Alain Nussbaumer 2025-05-04 16:51:15 +02:00
parent ae50fe548f
commit 4ecb19724a
10 changed files with 79 additions and 95 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -29,11 +29,9 @@ import NavbarBottom from '@/components/NavbarBottom.vue'
import NavbarTop from '@/components/NavbarTop.vue' import NavbarTop from '@/components/NavbarTop.vue'
import ReconnectingWebSocket from 'reconnectingwebsocket' import ReconnectingWebSocket from 'reconnectingwebsocket'
import configuration from '@/api/configuration' import configuration from '@/api/configuration'
import library from '@/api/library'
import services from '@/api/services' import services from '@/api/services'
import { useConfigurationStore } from '@/stores/configuration' import { useConfigurationStore } from '@/stores/configuration'
import { useLibraryStore } from '@/stores/library' import { useLibraryStore } from '@/stores/library'
import { useLyricsStore } from '@/stores/lyrics'
import { useNotificationsStore } from '@/stores/notifications' import { useNotificationsStore } from '@/stores/notifications'
import { useOutputsStore } from './stores/outputs' import { useOutputsStore } from './stores/outputs'
import { usePlayerStore } from '@/stores/player' import { usePlayerStore } from '@/stores/player'
@ -56,7 +54,6 @@ export default {
return { return {
configurationStore: useConfigurationStore(), configurationStore: useConfigurationStore(),
libraryStore: useLibraryStore(), libraryStore: useLibraryStore(),
lyricsStore: useLyricsStore(),
notificationsStore: useNotificationsStore(), notificationsStore: useNotificationsStore(),
outputsStore: useOutputsStore(), outputsStore: useOutputsStore(),
playerStore: usePlayerStore(), playerStore: usePlayerStore(),
@ -174,20 +171,19 @@ export default {
const data = JSON.parse(response.data) const data = JSON.parse(response.data)
const notify = new Set(data.notify || []) const notify = new Set(data.notify || [])
const handlers = [ const handlers = [
{ handler: this.updateLibrary, triggers: ['update', 'database'] }, { events: ['update', 'database'], handler: this.updateLibrary },
{ {
handler: this.updatePlayer, events: ['player', 'options', 'volume'],
triggers: ['player', 'options', 'volume'] handler: this.updatePlayer
}, },
{ handler: this.updateOutputs, triggers: ['outputs', 'volume'] }, { events: ['outputs', 'volume'], handler: this.updateOutputs },
{ handler: this.updateQueue, triggers: ['queue'] }, { events: ['queue'], handler: this.updateQueue },
{ handler: this.updateSpotify, triggers: ['spotify'] }, { events: ['spotify'], handler: this.updateSpotify },
{ handler: this.updateLastfm, triggers: ['lastfm'] }, { events: ['lastfm'], handler: this.updateLastfm },
{ handler: this.updateRemotes, triggers: ['pairing'] }, { events: ['pairing'], handler: this.updateRemotes }
{ handler: this.updateLyrics, triggers: ['player', 'queue'] }
] ]
handlers.forEach(({ handler, triggers }) => { handlers.forEach(({ handler, events }) => {
if (triggers.some((key) => notify.has(key))) { if (events.some((key) => notify.has(key))) {
handler.call(this) handler.call(this)
} }
}) })
@ -222,16 +218,6 @@ export default {
updateLibrary() { updateLibrary() {
this.libraryStore.initialise() this.libraryStore.initialise()
}, },
updateLyrics() {
const track = this.queueStore.current
if (track?.track_id) {
library.track(track.track_id).then((data) => {
this.lyricsStore.lyrics = data.lyrics
})
} else {
this.lyricsStore.$reset()
}
},
updateOutputs() { updateOutputs() {
this.outputsStore.initialise() this.outputsStore.initialise()
}, },

View File

@ -21,8 +21,8 @@ export default {
previous() { previous() {
return api.put('./api/player/previous') return api.put('./api/player/previous')
}, },
repeat(mode) { repeat(state) {
return api.put(`./api/player/repeat?state=${mode}`) return api.put(`./api/player/repeat?state=${state}`)
}, },
seek(seekMs) { seek(seekMs) {
return api.put(`./api/player/seek?seek_ms=${seekMs}`) return api.put(`./api/player/seek?seek_ms=${seekMs}`)

View File

@ -6,9 +6,6 @@ import { useQueueStore } from '@/stores/queue'
const { t } = i18n.global const { t } = i18n.global
export default { export default {
state() {
return api.get('./api/queue')
},
addUri(uris, next = false) { addUri(uris, next = false) {
return this.addToQueue({ uris }, next) return this.addToQueue({ uris }, next)
}, },
@ -59,6 +56,9 @@ export default {
remove(id) { remove(id) {
return api.delete(`./api/queue/items/${id}`) return api.delete(`./api/queue/items/${id}`)
}, },
state() {
return api.get('./api/queue')
},
async saveToPlaylist(name) { async saveToPlaylist(name) {
const response = await api.post('./api/queue/save', null, { const response = await api.post('./api/queue/save', null, {
params: { name } params: { name }

View File

@ -1,8 +1,5 @@
<template> <template>
<button <button :class="{ 'is-dark': playerStore.lyrics }" @click="toggle">
:class="{ 'is-dark': lyricsStore.active }"
@click="lyricsStore.toggle"
>
<mdicon <mdicon
class="icon" class="icon"
:name="icon" :name="icon"
@ -13,21 +10,26 @@
</template> </template>
<script> <script>
import { useLyricsStore } from '@/stores/lyrics' import { usePlayerStore } from '@/stores/player'
export default { export default {
name: 'ControlPlayerLyrics', name: 'ControlPlayerLyrics',
setup() { setup() {
return { return {
lyricsStore: useLyricsStore() playerStore: usePlayerStore()
} }
}, },
computed: { computed: {
icon() { icon() {
return this.lyricsStore.active return this.playerStore.lyrics
? 'script-text-play' ? 'script-text-play'
: 'script-text-outline' : 'script-text-outline'
} }
},
methods: {
toggle() {
this.playerStore.lyrics = !this.playerStore.lyrics
}
} }
} }
</script> </script>

View File

@ -31,13 +31,13 @@
</template> </template>
<script> <script>
import { useLyricsStore } from '@/stores/lyrics'
import { usePlayerStore } from '@/stores/player' import { usePlayerStore } from '@/stores/player'
import { useQueueStore } from '@/stores/queue'
export default { export default {
name: 'LyricsPane', name: 'LyricsPane',
setup() { setup() {
return { lyricsStore: useLyricsStore(), playerStore: usePlayerStore() } return { playerStore: usePlayerStore(), queueStore: useQueueStore() }
}, },
data() { data() {
/* /*
@ -54,7 +54,7 @@ export default {
}, },
computed: { computed: {
lyrics() { lyrics() {
const raw = this.lyricsStore.content const raw = this.playerStore.lyricsContent
const parsed = [] const parsed = []
if (raw.length > 0) { if (raw.length > 0) {
// Parse the lyrics // Parse the lyrics
@ -74,7 +74,8 @@ export default {
// Split the verses into words // Split the verses into words
parsed.forEach((verse, index, lyrics) => { parsed.forEach((verse, index, lyrics) => {
const unitDuration = const unitDuration =
(lyrics[index + 1].time - verse.time || 3) / verse.text.length ((lyrics[index + 1]?.time ?? verse.time + 3) - verse.time) /
verse.text.length
let delay = 0 let delay = 0
verse.words = verse.text.match(/\S+\s*/gu).map((text) => { verse.words = verse.text.match(/\S+\s*/gu).map((text) => {
const duration = text.length * unitDuration const duration = text.length * unitDuration

View File

@ -7,10 +7,10 @@
:url="track.artwork_url" :url="track.artwork_url"
:caption="track.album" :caption="track.album"
class="is-clickable is-big" class="is-clickable is-big"
:class="{ 'is-masked': lyricsStore.active }" :class="{ 'is-masked': playerStore.lyrics }"
@click="openDetails(track)" @click="openDetails(track)"
/> />
<lyrics-pane v-if="lyricsStore.active" /> <lyrics-pane v-if="playerStore.lyrics" />
<control-slider <control-slider
v-model:value="trackProgress" v-model:value="trackProgress"
class="mt-5" class="mt-5"
@ -56,7 +56,6 @@ import ControlSlider from '@/components/ControlSlider.vue'
import LyricsPane from '@/components/LyricsPane.vue' import LyricsPane from '@/components/LyricsPane.vue'
import ModalDialogQueueItem from '@/components/ModalDialogQueueItem.vue' import ModalDialogQueueItem from '@/components/ModalDialogQueueItem.vue'
import player from '@/api/player' import player from '@/api/player'
import { useLyricsStore } from '@/stores/lyrics'
import { usePlayerStore } from '@/stores/player' import { usePlayerStore } from '@/stores/player'
import { useQueueStore } from '@/stores/queue' import { useQueueStore } from '@/stores/queue'
import { useSettingsStore } from '@/stores/settings' import { useSettingsStore } from '@/stores/settings'
@ -73,7 +72,6 @@ export default {
}, },
setup() { setup() {
return { return {
lyricsStore: useLyricsStore(),
playerStore: usePlayerStore(), playerStore: usePlayerStore(),
queueStore: useQueueStore(), queueStore: useQueueStore(),
settingsStore: useSettingsStore() settingsStore: useSettingsStore()

View File

@ -1,13 +0,0 @@
import { defineStore } from 'pinia'
export const useLyricsStore = defineStore('LyricsStore', {
actions: {
toggle() {
this.active = !this.active
}
},
state: () => ({
content: [],
active: false
})
})

View File

@ -1,10 +1,18 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import library from '@/api/library'
import player from '@/api/player' import player from '@/api/player'
import { useQueueStore } from '@/stores/queue'
export const usePlayerStore = defineStore('PlayerStore', { export const usePlayerStore = defineStore('PlayerStore', {
actions: { actions: {
async initialise() { async initialise() {
this.$state = await player.state() this.$state = await player.state()
const queueStore = useQueueStore()
if (queueStore.current.track_id) {
library.track(queueStore.current.track_id).then((data) => {
this.lyricsContent = data.lyrics || ''
})
}
} }
}, },
getters: { getters: {
@ -19,6 +27,8 @@ export const usePlayerStore = defineStore('PlayerStore', {
item_id: 0, item_id: 0,
item_length_ms: 0, item_length_ms: 0,
item_progress_ms: 0, item_progress_ms: 0,
lyrics: false,
lyricsContent: '',
repeat: 'off', repeat: 'off',
shuffle: false, shuffle: false,
state: 'stop', state: 'stop',