diff --git a/client/src/components/Table.vue b/client/src/components/Table.vue index aa5f918..c92b646 100644 --- a/client/src/components/Table.vue +++ b/client/src/components/Table.vue @@ -2,13 +2,13 @@ - + - @@ -16,11 +16,8 @@ \ No newline at end of file diff --git a/client/src/components/TickComponent.vue b/client/src/components/TickComponent.vue index 8681322..cd3ffcb 100644 --- a/client/src/components/TickComponent.vue +++ b/client/src/components/TickComponent.vue @@ -1,9 +1,23 @@ \ No newline at end of file diff --git a/client/src/state.ts b/client/src/state.ts new file mode 100644 index 0000000..2b03738 --- /dev/null +++ b/client/src/state.ts @@ -0,0 +1,33 @@ +import { reactive } from "vue" +import { Track } from "./track" +import { error } from "./error" + +export const state = reactive({ + tracks: new Array, + isPopulating: false, + async populate() { + if (this.isPopulating) return + this.isPopulating = true + this.tracks = await Track.fetchAll() + this.isPopulating = false + }, + async taskCompleted(track: Track): Promise { + const result = await fetch(`/api/v1/tracks/${track.id}/ticked`, { method: "PATCH" }) + const body = await result.text() + if (!result.ok) { + error(body) + throw new Error(`error setting tick for track ${track.id} ("${track.name}"): ${result.status} ${result.statusText}`) + } + const tick: Tick = JSON.parse(body) + track.ticks = track.ticks ?? [] + track.ticks.push(tick) + const tracks = this.tracks.map($track => track.id === $track.id ? track : $track) + this.tracks = tracks + return tick + }, + async taskMarkedIncomplete(tick: Tick) { + const { ok, status, statusText } = await fetch(`/api/v1/ticks/${tick.id}`, { method: 'DELETE' }) + if (!ok) + error(`error deleting tick ${tick.id}: ${statusText} (${status})`) + } +}) \ No newline at end of file diff --git a/client/src/track.ts b/client/src/track.ts index 4ce889d..13c2174 100644 --- a/client/src/track.ts +++ b/client/src/track.ts @@ -85,7 +85,6 @@ export class Track implements ITrack { console.error(e) console.debug(body) } - } catch (err) { console.error(err) result.text()
Date{{ track.icon }}{{ track.icon }}
{{ dateString(date) }} - + +