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'