From 5c769bfa2fb4eaa3289ce6172c42d98538ca2609 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Sun, 31 Dec 2023 02:39:01 +0100 Subject: [PATCH] Tasks: print newly added tasks, fixed some bugs --- frontend/src/components/TrackerTimer.vue | 21 +++++++++++++++++---- frontend/src/stores/AppStore.js | 16 ++++++++++++++++ frontend/src/views/TrackerView.vue | 15 +++++++++++++-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/TrackerTimer.vue b/frontend/src/components/TrackerTimer.vue index 3ab943b..90c0708 100644 --- a/frontend/src/components/TrackerTimer.vue +++ b/frontend/src/components/TrackerTimer.vue @@ -44,21 +44,34 @@ export default { } }, methods: { - startStopTimer() { + async startStopTimer() { if (this.timerState == 'Start') { this.timerState = 'Stop' this.task.startTime = Date.now() + this.timeNow = Date.now() console.log('timer started') this.timer = setInterval(() => { this.timeNow = Date.now() }, 1000) } else { - this.timerState = 'Start' this.task.stopTime = Date.now() + this.timerState = 'Start' clearInterval(this.timer) this.timer = undefined - AppStore.data.newTask = this.task - console.log(AppStore.data.newTask) + this.timeNow = 0 + AppStore.data.newTask = { + title: this.task.title, + timeStart: this.task.startTime, + timeEnd: this.task.stopTime + } + await AppStore.sendAdd(AppStore.data.newTask, '/task/add') + + this.task = { + startTime: 0, + stopTime: 0, + title: '' + } + this.$emit('get-tasks') } } } diff --git a/frontend/src/stores/AppStore.js b/frontend/src/stores/AppStore.js index fe725b9..db189ec 100644 --- a/frontend/src/stores/AppStore.js +++ b/frontend/src/stores/AppStore.js @@ -31,5 +31,21 @@ export default { } catch (error) { console.error('Error fetching data:', error) } + }, + async sendAdd(data, url) { + try { + const response = await fetch(this.api_url + url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }) + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`) + } + } catch (error) { + console.error('Error sending data:', error) + } } } diff --git a/frontend/src/views/TrackerView.vue b/frontend/src/views/TrackerView.vue index 5f020d6..1f300ec 100644 --- a/frontend/src/views/TrackerView.vue +++ b/frontend/src/views/TrackerView.vue @@ -6,11 +6,11 @@ import TaskRecord from '@/components/TaskRecord.vue'