mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-16 12:12:15 +01:00
cleanup dayjs abstraction usage and useCurrentTimeEntry api for starting and stopping time entries
This commit is contained in:
@@ -4,8 +4,8 @@ import TimeTrackerStartStop from '@/packages/ui/src/TimeTrackerStartStop.vue';
|
|||||||
import { useProjectsStore } from '@/utils/useProjects';
|
import { useProjectsStore } from '@/utils/useProjects';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import { useCurrentTimeEntryStore } from '@/utils/useCurrentTimeEntry';
|
import { useCurrentTimeEntryStore } from '@/utils/useCurrentTimeEntry';
|
||||||
|
import { getDayJsInstance } from '@/packages/ui/src/utils/time';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
title: string;
|
title: string;
|
||||||
@@ -20,16 +20,16 @@ const project = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { currentTimeEntry } = storeToRefs(useCurrentTimeEntryStore());
|
const { currentTimeEntry } = storeToRefs(useCurrentTimeEntryStore());
|
||||||
const { stopTimer, startTimer } = useCurrentTimeEntryStore();
|
const { setActiveState } = useCurrentTimeEntryStore();
|
||||||
|
|
||||||
async function startTaskTimer() {
|
async function startTaskTimer() {
|
||||||
if (currentTimeEntry.value.id) {
|
if (currentTimeEntry.value.id) {
|
||||||
await stopTimer();
|
await setActiveState(true);
|
||||||
}
|
}
|
||||||
currentTimeEntry.value.project_id = props.project_id;
|
currentTimeEntry.value.project_id = props.project_id;
|
||||||
currentTimeEntry.value.task_id = props.task_id;
|
currentTimeEntry.value.task_id = props.task_id;
|
||||||
currentTimeEntry.value.start = dayjs().utc().format();
|
currentTimeEntry.value.start = getDayJsInstance().utc().format();
|
||||||
await startTimer();
|
await setActiveState(true);
|
||||||
useCurrentTimeEntryStore().fetchCurrentTimeEntry();
|
useCurrentTimeEntryStore().fetchCurrentTimeEntry();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ const loadMoreContainer = ref<HTMLDivElement | null>(null);
|
|||||||
const isLoadMoreVisible = useElementVisibility(loadMoreContainer);
|
const isLoadMoreVisible = useElementVisibility(loadMoreContainer);
|
||||||
const currentTimeEntryStore = useCurrentTimeEntryStore();
|
const currentTimeEntryStore = useCurrentTimeEntryStore();
|
||||||
const { currentTimeEntry } = storeToRefs(currentTimeEntryStore);
|
const { currentTimeEntry } = storeToRefs(currentTimeEntryStore);
|
||||||
const { stopTimer } = currentTimeEntryStore;
|
const { setActiveState } = currentTimeEntryStore;
|
||||||
const { tags } = storeToRefs(useTagsStore());
|
const { tags } = storeToRefs(useTagsStore());
|
||||||
|
|
||||||
async function startTimeEntry(
|
async function startTimeEntry(
|
||||||
timeEntry: Omit<CreateTimeEntryBody, 'member_id'>
|
timeEntry: Omit<CreateTimeEntryBody, 'member_id'>
|
||||||
) {
|
) {
|
||||||
if (currentTimeEntry.value.id) {
|
if (currentTimeEntry.value.id) {
|
||||||
await stopTimer();
|
await setActiveState(false);
|
||||||
}
|
}
|
||||||
await createTimeEntry(timeEntry);
|
await createTimeEntry(timeEntry);
|
||||||
fetchTimeEntries();
|
fetchTimeEntries();
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
import TimeEntryAggregateRow from '@/packages/ui/src/TimeEntry/TimeEntryAggregateRow.vue';
|
import TimeEntryAggregateRow from '@/packages/ui/src/TimeEntry/TimeEntryAggregateRow.vue';
|
||||||
import TimeEntryRowHeading from '@/packages/ui/src/TimeEntry/TimeEntryRowHeading.vue';
|
import TimeEntryRowHeading from '@/packages/ui/src/TimeEntry/TimeEntryRowHeading.vue';
|
||||||
import TimeEntryRow from '@/packages/ui/src/TimeEntry/TimeEntryRow.vue';
|
import TimeEntryRow from '@/packages/ui/src/TimeEntry/TimeEntryRow.vue';
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import type { TimeEntriesGroupedByType } from '@/types/time-entries';
|
import type { TimeEntriesGroupedByType } from '@/types/time-entries';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -106,7 +105,7 @@ function startTimeEntryFromExisting(entry: TimeEntry) {
|
|||||||
props.createTimeEntry({
|
props.createTimeEntry({
|
||||||
project_id: entry.project_id,
|
project_id: entry.project_id,
|
||||||
task_id: entry.task_id,
|
task_id: entry.task_id,
|
||||||
start: dayjs().utc().format(),
|
start: getDayJsInstance().utc().format(),
|
||||||
end: null,
|
end: null,
|
||||||
billable: entry.billable,
|
billable: entry.billable,
|
||||||
description: entry.description,
|
description: entry.description,
|
||||||
|
|||||||
@@ -205,8 +205,6 @@ export const useCurrentTimeEntryStore = defineStore('currentTimeEntry', () => {
|
|||||||
return {
|
return {
|
||||||
currentTimeEntry,
|
currentTimeEntry,
|
||||||
fetchCurrentTimeEntry,
|
fetchCurrentTimeEntry,
|
||||||
startTimer,
|
|
||||||
stopTimer,
|
|
||||||
updateTimer,
|
updateTimer,
|
||||||
isActive,
|
isActive,
|
||||||
startLiveTimer,
|
startLiveTimer,
|
||||||
|
|||||||
Reference in New Issue
Block a user