Add event handlers for updates to tracks

This commit is contained in:
D. Scott Boggs 2023-06-25 14:43:34 -04:00
parent 678e95bba0
commit 6360f23209

View file

@ -38,8 +38,11 @@ export const state = reactive({
})
this.tracks = tracks
})
source.addEventListener('TrackAdded', ({ data }) => {
const track: Track = JSON.parse(data)
this.tracks = [track, ...this.tracks]
})
source.addEventListener('TickDropped', event => {
console.log(event)
const tick: Tick = JSON.parse(event.data)
const tracks = this.tracks.map(track => {
if (track.id === tick.track_id) {
@ -49,6 +52,14 @@ export const state = reactive({
})
this.tracks = tracks
})
source.addEventListener('TrackDropped', ({ data }) => {
const track: Track = JSON.parse(data)
this.tracks = this.tracks.filter($track => $track.id !== track.id)
})
source.addEventListener('TrackChanged', ({ data }) => {
const track: Track = JSON.parse(data)
this.tracks = this.tracks.map($track => $track.id === track.id ? track : $track)
})
source.addEventListener('Lagged', event => {
console.log(event)
// Refresh the page, refetching the list of tracks and ticks