From 6360f23209a6e76a29bf2e7a5a50ab18fa59343d Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Sun, 25 Jun 2023 14:43:34 -0400 Subject: [PATCH] Add event handlers for updates to tracks --- client/src/state.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/src/state.ts b/client/src/state.ts index 1995cc5..15c74a8 100644 --- a/client/src/state.ts +++ b/client/src/state.ts @@ -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