diff --git a/frontend/src/components/tracking/timeTrackerLine.vue b/frontend/src/components/tracking/timeTrackerLine.vue
index b4220fb..a70dd25 100644
--- a/frontend/src/components/tracking/timeTrackerLine.vue
+++ b/frontend/src/components/tracking/timeTrackerLine.vue
@@ -1,131 +1,227 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+watch(timerRunning, newVal => {
+ if (!newVal && timerStore.intervalId) {
+ clearInterval(timerStore.intervalId)
+ timerStore.intervalId = null
+ }
+})
+
\ No newline at end of file
diff --git a/frontend/src/components/tracking/timeTrackingItem.vue b/frontend/src/components/tracking/timeTrackingItem.vue
index ad628ba..3d42a5d 100644
--- a/frontend/src/components/tracking/timeTrackingItem.vue
+++ b/frontend/src/components/tracking/timeTrackingItem.vue
@@ -40,7 +40,6 @@ defineComponent({
const emit = defineEmits(['delete'])
-
interface Props {
timeEntry: TimeTrackingItem
}
@@ -54,12 +53,13 @@ const itemDate = computed(() => {
const timeFrom = computed(() => {
const date = new Date(props.timeEntry.start_time)
- return date.toISOString().substr(11, 5)
+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false })
})
+
const timeTo = computed(() => {
const date = new Date(props.timeEntry.end_time)
- return date.toISOString().substr(11, 5)
+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false })
})
const duration = computed(() => {
@@ -75,6 +75,4 @@ const task = computed(() => {
return props.timeEntry.task
})
-
-
diff --git a/frontend/src/stores/timerStore.ts b/frontend/src/stores/timerStore.ts
new file mode 100644
index 0000000..d3133c5
--- /dev/null
+++ b/frontend/src/stores/timerStore.ts
@@ -0,0 +1,54 @@
+import { defineStore } from 'pinia';
+import { ref } from 'vue';
+export const useTimerStore = defineStore('timer', () => {
+ const timerRunning = ref(false);
+ const selectedDate = ref('');
+ const timeFrom = ref('');
+ const timeTo = ref('');
+ const selectedProject = ref('');
+ const isNotificationVisible = ref(false);
+ const notificationRef = ref<(() => void) | null>(null);
+ const intervalId = ref | null>(null);
+
+ function startTimer(project: string) {
+ const currentTime = new Date();
+ selectedDate.value = currentTime.toISOString().slice(0, 10);
+ timeFrom.value = formatTime(currentTime);
+ timeTo.value = formatTime(currentTime);
+ selectedProject.value = project;
+ timerRunning.value = true;
+ }
+
+ function stopTimer() {
+ timerRunning.value = false;
+ }
+
+ function calculateDuration() {
+ const timeStart = new Date(`01/01/2007 ${timeFrom.value}`);
+ const timeEnd = new Date(`01/01/2007 ${timeTo.value}`);
+ const diff = Number(timeEnd) - Number(timeStart);
+ return Math.floor(diff / 1000 / 60);
+ }
+
+ function formatTime(date: Date) {
+ return date.toLocaleTimeString([], {
+ hour: '2-digit',
+ minute: '2-digit',
+ hour12: false,
+ });
+ }
+
+ return {
+ timerRunning,
+ selectedDate,
+ timeFrom,
+ timeTo,
+ selectedProject,
+ isNotificationVisible,
+ notificationRef,
+ intervalId,
+ startTimer,
+ stopTimer,
+ calculateDuration,
+ };
+});