Fix calling createTrack multiple times when radio track changes
This commit is contained in:
parent
c828e106b0
commit
f06464ffa2
|
@ -35,11 +35,11 @@ const {
|
||||||
currentTrack,
|
currentTrack,
|
||||||
currentIndex,
|
currentIndex,
|
||||||
queue,
|
queue,
|
||||||
tracks,
|
|
||||||
dequeue,
|
dequeue,
|
||||||
playTrack,
|
playTrack,
|
||||||
reorder,
|
reorder,
|
||||||
endsIn: timeLeft
|
endsIn: timeLeft,
|
||||||
|
clear
|
||||||
} = useQueue()
|
} = useQueue()
|
||||||
|
|
||||||
const queueModal = ref()
|
const queueModal = ref()
|
||||||
|
@ -291,7 +291,7 @@ const reorderTracks = async (from: number, to: number) => {
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="ui right floated basic button danger"
|
class="ui right floated basic button danger"
|
||||||
@click="tracks.length = 0"
|
@click="clear"
|
||||||
>
|
>
|
||||||
<translate translate-context="*/Queue/*/Verb">
|
<translate translate-context="*/Queue/*/Verb">
|
||||||
Clear
|
Clear
|
||||||
|
|
|
@ -27,14 +27,12 @@ const running = computed(() => {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return store.state.radios.current?.type === props.type
|
const { current } = store.state.radios
|
||||||
&& store.state.radios.current?.customRadioId === props.customRadioId
|
return current?.type === props.type
|
||||||
|
&& current?.customRadioId === props.customRadioId
|
||||||
&& (
|
&& (
|
||||||
typeof props.objectId === 'string'
|
(typeof props.objectId === 'object' && current.objectId?.fullUsername === props.objectId?.fullUsername)
|
||||||
|| (
|
|| current.objectId === props.objectId
|
||||||
typeof props.objectId !== 'number'
|
|
||||||
&& store.state.radios.current?.objectId?.fullUsername === props.objectId?.fullUsername
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -235,6 +235,12 @@ export const useQueue = createGlobalState(() => {
|
||||||
return date
|
return date
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// Clear
|
||||||
|
const clear = () => {
|
||||||
|
store.commit('radios/reset')
|
||||||
|
tracks.value.length = 0
|
||||||
|
}
|
||||||
|
|
||||||
// Radio queue populating
|
// Radio queue populating
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (store.state.radios.running && currentIndex.value === tracks.value.length - 1) {
|
if (store.state.radios.running && currentIndex.value === tracks.value.length - 1) {
|
||||||
|
@ -260,6 +266,7 @@ export const useQueue = createGlobalState(() => {
|
||||||
shuffle,
|
shuffle,
|
||||||
reshuffleUpcomingTracks,
|
reshuffleUpcomingTracks,
|
||||||
reorder,
|
reorder,
|
||||||
endsIn
|
endsIn,
|
||||||
|
clear
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type { Sound } from '~/api/player'
|
||||||
|
|
||||||
import { soundImplementation } from '~/api/player'
|
import { soundImplementation } from '~/api/player'
|
||||||
import { createGlobalState, syncRef } from '@vueuse/core'
|
import { createGlobalState, syncRef } from '@vueuse/core'
|
||||||
import { computed, ref, watchEffect } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
|
|
||||||
import { useQueue } from '~/composables/audio/queue'
|
import { useQueue } from '~/composables/audio/queue'
|
||||||
import { connectAudioSource } from '~/composables/audio/audio-api'
|
import { connectAudioSource } from '~/composables/audio/audio-api'
|
||||||
|
@ -113,7 +113,7 @@ export const useTracks = createGlobalState(() => {
|
||||||
// NOTE: We want to have it called only once, hence we're using createGlobalState
|
// NOTE: We want to have it called only once, hence we're using createGlobalState
|
||||||
const initialize = createGlobalState(() => {
|
const initialize = createGlobalState(() => {
|
||||||
const { currentTrack: track, currentIndex } = useQueue()
|
const { currentTrack: track, currentIndex } = useQueue()
|
||||||
watchEffect(async () => createTrack(currentIndex.value))
|
watch(currentIndex, (index) => createTrack(index))
|
||||||
syncRef(currentTrack, track)
|
syncRef(currentTrack, track)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ export interface PlayOptionsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (props: PlayOptionsProps) => {
|
export default (props: PlayOptionsProps) => {
|
||||||
const { enqueue: addToQueue, currentTrack, playNext, currentIndex, enqueueAt, queue, tracks, playTrack } = useQueue()
|
const { enqueue: addToQueue, currentTrack, playNext, currentIndex, enqueueAt, queue, clear, playTrack } = useQueue()
|
||||||
const { isPlaying } = usePlayer()
|
const { isPlaying } = usePlayer()
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ export default (props: PlayOptionsProps) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const replacePlay = async () => {
|
const replacePlay = async () => {
|
||||||
tracks.value.length = 0
|
clear()
|
||||||
|
|
||||||
jQuery(el.value).find('.ui.dropdown').dropdown('hide')
|
jQuery(el.value).find('.ui.dropdown').dropdown('hide')
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,16 @@ export const install: InitModule = ({ store, router }) => {
|
||||||
|
|
||||||
switch (error.response?.status) {
|
switch (error.response?.status) {
|
||||||
case 404:
|
case 404:
|
||||||
|
if (error.response?.data === 'Radio doesn\'t have more candidates') {
|
||||||
|
error.backendErrors.push(error.response.data)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
error.backendErrors.push('Resource not found')
|
error.backendErrors.push('Resource not found')
|
||||||
error.isHandled = true
|
error.isHandled = true
|
||||||
store.commit('ui/addMessage', {
|
store.commit('ui/addMessage', {
|
||||||
// @ts-expect-error TS does not know about .data structure
|
// @ts-expect-error TS does not know about .data structure
|
||||||
content: error.response?.data?.detail ?? error.response?.data,
|
content: error.response?.data?.detail ?? error.response?.data ?? 'Resource not found',
|
||||||
class: 'error'
|
class: 'error'
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
import type { BackendError, Track } from '~/types'
|
||||||
import type { RootState } from '~/store/index'
|
import type { RootState } from '~/store/index'
|
||||||
import type { Module } from 'vuex'
|
import type { Module } from 'vuex'
|
||||||
import type { Track } from '~/types'
|
|
||||||
|
|
||||||
import { useQueue } from '~/composables/audio/queue'
|
import { useQueue } from '~/composables/audio/queue'
|
||||||
import { usePlayer } from '~/composables/audio/player'
|
import { usePlayer } from '~/composables/audio/player'
|
||||||
|
@ -144,7 +144,14 @@ const store: Module<State, RootState> = {
|
||||||
isPlaying.value = true
|
isPlaying.value = true
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Error while adding track to queue from radio', error)
|
if ((error as BackendError).backendErrors?.[0] === 'Radio doesn\'t have more candidates') {
|
||||||
|
commit('ui/addMessage', {
|
||||||
|
content: (error as BackendError).backendErrors?.[0]
|
||||||
|
}, { root: true })
|
||||||
|
} else {
|
||||||
|
logger.error('Error while adding track to queue from radio', error)
|
||||||
|
}
|
||||||
|
|
||||||
commit('reset')
|
commit('reset')
|
||||||
} finally {
|
} finally {
|
||||||
state.populating = false
|
state.populating = false
|
||||||
|
|
Loading…
Reference in New Issue