mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
make sure that 404 current time entry requests do not override local
state while preparing new time entry
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { computed, reactive, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { api } from '@/packages/api/src';
|
import { api } from '@/packages/api/src';
|
||||||
import type { TimeEntry } from '@/packages/api/src';
|
import type { TimeEntry } from '@/packages/api/src';
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
@@ -30,7 +30,7 @@ const emptyTimeEntry = {
|
|||||||
} as TimeEntry;
|
} as TimeEntry;
|
||||||
|
|
||||||
export const useCurrentTimeEntryStore = defineStore('currentTimeEntry', () => {
|
export const useCurrentTimeEntryStore = defineStore('currentTimeEntry', () => {
|
||||||
const currentTimeEntry = ref<TimeEntry>(reactive(emptyTimeEntry));
|
const currentTimeEntry = ref<TimeEntry>({ ...emptyTimeEntry });
|
||||||
const { handleApiRequestNotifications } = useNotificationsStore();
|
const { handleApiRequestNotifications } = useNotificationsStore();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -74,11 +74,23 @@ export const useCurrentTimeEntryStore = defineStore('currentTimeEntry', () => {
|
|||||||
startLiveTimer();
|
startLiveTimer();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentTimeEntry.value = { ...emptyTimeEntry };
|
// No active time entry on server
|
||||||
|
// Only reset if we had a previously started timer (has an ID)
|
||||||
|
// Don't reset if user is preparing a new time entry (no ID yet)
|
||||||
|
if (currentTimeEntry.value.id !== '') {
|
||||||
|
currentTimeEntry.value = { ...emptyTimeEntry };
|
||||||
|
stopLiveTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
currentTimeEntry.value = { ...emptyTimeEntry };
|
// API error (e.g., 404 when no active time entry)
|
||||||
|
// Only reset if we had a previously started timer (has an ID)
|
||||||
|
// Don't reset if user is preparing a new time entry (no ID yet)
|
||||||
|
if (currentTimeEntry.value.id !== '') {
|
||||||
|
currentTimeEntry.value = { ...emptyTimeEntry };
|
||||||
|
stopLiveTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
Reference in New Issue
Block a user