diff --git a/Makefile b/Makefile index 274c3d3..bc6334b 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,5 @@ start-server: build-client clean: docker compose down - rm -r server/public/ client/dist/ + -rm -r server/public/ client/dist/ + diff --git a/client/src/components/NavBar.vue b/client/src/components/NavBar.vue index e11af91..64a6d6e 100644 --- a/client/src/components/NavBar.vue +++ b/client/src/components/NavBar.vue @@ -1,5 +1,14 @@ \ No newline at end of file + diff --git a/client/src/state.ts b/client/src/state.ts index 13e3312..9e08abb 100644 --- a/client/src/state.ts +++ b/client/src/state.ts @@ -2,6 +2,7 @@ import { reactive } from "vue" import { Track } from "./track" import { Tick } from './ticks' import { error } from "./error" +import { getCookie } from "./util"; enum State { Unfetched, @@ -26,10 +27,13 @@ class AppState { tracks: Array state: State user?: LoggedInUser + source?: EventSource constructor() { this.tracks = new Array this.state = State.Unfetched + const name = getCookie("name") + if (name) this.user = { name } } streamUpdatesFromServer() { const source = new EventSource("/api/v1/updates") @@ -79,16 +83,22 @@ class AppState { window.location = window.location }) window.addEventListener('beforeunload', () => source.close()) + this.source = source } async repopulate() { + if (!this.user) { + this.tracks = [] + return + } this.state = State.Fetching this.tracks = await Track.fetchAll() + this.source?.close() + this.streamUpdatesFromServer() + this.state = State.Fetched } async populate() { if (this.state != State.Unfetched) return await this.repopulate() - this.streamUpdatesFromServer() - this.state = State.Fetched } async taskCompleted(track: Track, date: Date): Promise { const query = dateQuery(date) diff --git a/client/src/track.ts b/client/src/track.ts index 83947a3..9893eca 100644 --- a/client/src/track.ts +++ b/client/src/track.ts @@ -1,4 +1,5 @@ import { error } from "./error" +import { Tick, ITick } from './ticks' export interface ITrack { id?: number @@ -97,4 +98,4 @@ export class Track implements ITrack { } return [] } -} \ No newline at end of file +} diff --git a/client/src/util.ts b/client/src/util.ts new file mode 100644 index 0000000..ebbda1c --- /dev/null +++ b/client/src/util.ts @@ -0,0 +1,8 @@ +export function getCookie(key: string): string | null { + const start = document.cookie.indexOf(key + '=') + if(start === -1) return null + let end: number | undefined = document.cookie.indexOf(';', start) + if(end === -1) + end = undefined + return document.cookie.substring(start + key.length + 1, end) +} \ No newline at end of file diff --git a/client/src/views/Login.vue b/client/src/views/Login.vue index 2ef2efe..a50bf9d 100644 --- a/client/src/views/Login.vue +++ b/client/src/views/Login.vue @@ -1,32 +1,47 @@