From e33ce8b1a8b7b3ff3aa492bb060883fd6f3e221e Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Tue, 20 Jun 2023 08:54:03 -0400 Subject: [PATCH] Fix updates --- client/src/components/TickComponent.vue | 2 +- client/src/state.ts | 45 ++++++++++++++----------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/client/src/components/TickComponent.vue b/client/src/components/TickComponent.vue index 29e7abc..7fc1ae0 100644 --- a/client/src/components/TickComponent.vue +++ b/client/src/components/TickComponent.vue @@ -9,7 +9,7 @@ import { Track } from '../track'; const props = defineProps<{ date: Date, track: Track }>() -const isSet = computed(() => props.track.isSetOn(props.date)) +const isSet = computed(() => state.tracks.find(track => track.id === props.track.id)?.isSetOn(props.date)) const className = computed(() => isSet.value ? "button is-rounded is-info" : "button is-rounded") diff --git a/client/src/state.ts b/client/src/state.ts index 90f7c2b..e0ad4ad 100644 --- a/client/src/state.ts +++ b/client/src/state.ts @@ -18,33 +18,38 @@ export const state = reactive({ source.addEventListener('TickAdded', event => { console.log(event) const tick: Tick = JSON.parse(event.data) - for (const track of this.tracks) { - if (track.id === tick.track_id) { - console.debug('pushing tick') - track.ticks?.push(tick) - } - } - // this.tracks = this.tracks.map(track => { + // for (const track of this.tracks) { // if (track.id === tick.track_id) { - // const ticks = track.ticks ?? [] - // ticks.push(tick) - // track.ticks = ticks + // console.debug('pushing tick') + // track.ticks?.push(tick) // } - // return track - // }) + // } + const tracks = this.tracks.map(track => { + if (track.id === tick.track_id) { + const ticks = track.ticks ?? [] + ticks.push(tick) + track.ticks = ticks + + } + return track + }) + console.debug(tracks) + this.tracks = tracks }) source.addEventListener('TickDropped', event => { console.log(event) const tick: Tick = JSON.parse(event.data) - for (const track of this.tracks) - if (track.id === tick.track_id) - track.ticks = track.ticks?.filter($tick => $tick.id === tick.id) - // this.tracks = this.tracks.map(track => { - // if (track.id === tick.track_id) { + // for (const track of this.tracks) + // if (track.id === tick.track_id) // track.ticks = track.ticks?.filter($tick => $tick.id === tick.id) - // } - // return track - // }) + const tracks = this.tracks.map(track => { + if (track.id === tick.track_id) { + track.ticks = track.ticks?.filter($tick => $tick.id !== tick.id) + } + return track + }) + console.debug(tracks) + this.tracks = tracks }) source.addEventListener('Lagged', event => { console.log(event)