diff --git a/resources/js/Components/Common/TimeEntry/TimeEntryRangeSelector.vue b/resources/js/Components/Common/TimeEntry/TimeEntryRangeSelector.vue
index 2d6595fa..75977a56 100644
--- a/resources/js/Components/Common/TimeEntry/TimeEntryRangeSelector.vue
+++ b/resources/js/Components/Common/TimeEntry/TimeEntryRangeSelector.vue
@@ -1,35 +1,15 @@
@@ -49,26 +29,13 @@ const open = ref(false);
-
+ emit('changed', newStart, newEnd)
+ "
+ :start="start"
+ :end="end">
+
diff --git a/resources/js/Components/Common/TimePicker.vue b/resources/js/Components/Common/TimePicker.vue
index c1784e43..8181de42 100644
--- a/resources/js/Components/Common/TimePicker.vue
+++ b/resources/js/Components/Common/TimePicker.vue
@@ -17,11 +17,11 @@ const props = withDefaults(
);
const hours = computed(() => {
- return model.value ? getLocalizedDayJs(model.value).hour() : null;
+ return model.value ? getLocalizedDayJs(model.value).format('HH') : null;
});
const minutes = computed(() => {
- return model.value ? getLocalizedDayJs(model.value).minute() : null;
+ return model.value ? getLocalizedDayJs(model.value).format('mm') : null;
});
function updateMinutes(event: Event) {
@@ -45,6 +45,8 @@ function updateHours(event: Event) {
.format();
}
}
+
+const emit = defineEmits(['changed']);
@@ -59,6 +61,8 @@ function updateHours(event: Event) {
+import { defineProps, ref, watch } from 'vue';
+import TimePicker from '@/Components/Common/TimePicker.vue';
+import { useFocusWithin } from '@vueuse/core';
+
+const props = defineProps<{
+ start: string;
+ end: string | null;
+}>();
+
+const emit = defineEmits(['changed']);
+const tempStart = ref(props.start);
+const tempEnd = ref(props.end || null);
+
+watch(props, () => {
+ tempStart.value = props.start;
+ tempEnd.value = props.end;
+});
+function updateTimeEntry() {
+ if (tempStart.value !== props.start || tempEnd.value !== props.end) {
+ emit('changed', tempStart.value, tempEnd.value);
+ }
+}
+
+const dropdownContent = ref();
+const { focused } = useFocusWithin(dropdownContent);
+
+watch(focused, (newValue, oldValue) => {
+ if (oldValue === true && newValue === false) {
+ updateTimeEntry();
+ }
+});
+
+
+
+
+
+
+
diff --git a/resources/js/Components/Common/TimeTracker/TimeTrackerRangeSelector.vue b/resources/js/Components/Common/TimeTracker/TimeTrackerRangeSelector.vue
new file mode 100644
index 00000000..d340b524
--- /dev/null
+++ b/resources/js/Components/Common/TimeTracker/TimeTrackerRangeSelector.vue
@@ -0,0 +1,148 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/js/Components/TimeTracker.vue b/resources/js/Components/TimeTracker.vue
index 43e5807e..759ae6ef 100644
--- a/resources/js/Components/TimeTracker.vue
+++ b/resources/js/Components/TimeTracker.vue
@@ -5,19 +5,19 @@ import BillableToggleButton from '@/Components/Common/BillableToggleButton.vue';
import TimeTrackerStartStop from '@/Components/Common/TimeTrackerStartStop.vue';
import { usePage } from '@inertiajs/vue3';
import { type User } from '@/types/models';
-import { computed, onMounted, ref, watch } from 'vue';
+import { computed, onMounted, watch } from 'vue';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import duration from 'dayjs/plugin/duration';
import { useCurrentTimeEntryStore } from '@/utils/useCurrentTimeEntry';
import { storeToRefs } from 'pinia';
-import parse from 'parse-duration';
import TimeTrackerTagDropdown from '@/Components/Common/TimeTracker/TimeTrackerTagDropdown.vue';
import TimeTrackerProjectTaskDropdown from '@/Components/Common/TimeTracker/TimeTrackerProjectTaskDropdown.vue';
import { getCurrentOrganizationId } from '@/utils/useUser';
import { switchOrganization } from '@/utils/useOrganization';
import SecondaryButton from '@/Components/SecondaryButton.vue';
+import TimeTrackerRangeSelector from '@/Components/Common/TimeTracker/TimeTrackerRangeSelector.vue';
const page = usePage<{
auth: {
@@ -41,30 +41,6 @@ watch(isActive, () => {
}
});
-const temporaryCustomTimerEntry = ref('');
-
-const currentTime = computed({
- get() {
- if (temporaryCustomTimerEntry.value !== '') {
- return temporaryCustomTimerEntry.value;
- }
- if (now.value && currentTimeEntry.value.start) {
- const startTime = dayjs(currentTimeEntry.value.start);
- const diff = now.value.diff(startTime);
- return dayjs(diff).utc().format('HH:mm:ss');
- }
- return null;
- },
- // setter
- set(newValue) {
- if (newValue) {
- temporaryCustomTimerEntry.value = newValue;
- } else {
- temporaryCustomTimerEntry.value = '';
- }
- },
-});
-
onMounted(async () => {
if (page.props.auth.user.current_team_id) {
await currentTimeEntryStore.fetchCurrentTimeEntry();
@@ -78,80 +54,12 @@ function updateTimeEntry() {
}
}
-function pauseLiveTimerUpdate() {
- stopLiveTimer();
-}
-
-function updateTimerAndStartLiveTimerUpdate() {
- const time = parse(temporaryCustomTimerEntry.value, 's');
-
- if (isNumeric(temporaryCustomTimerEntry.value)) {
- const newStartDate = dayjs().subtract(
- parseInt(temporaryCustomTimerEntry.value),
- 'm'
- );
- currentTimeEntry.value.start = newStartDate.utc().format();
- if (currentTimeEntry.value.id !== '') {
- currentTimeEntryStore.updateTimer();
- } else {
- currentTimeEntryStore.startTimer();
- }
- } else if (isHHMM(temporaryCustomTimerEntry.value)) {
- const results = parseHHMM(temporaryCustomTimerEntry.value);
- if (results) {
- const newStartDate = dayjs()
- .subtract(parseInt(results[1]), 'h')
- .subtract(parseInt(results[2]), 'm');
- currentTimeEntry.value.start = newStartDate.utc().format();
- if (currentTimeEntry.value.id !== '') {
- currentTimeEntryStore.updateTimer();
- } else {
- currentTimeEntryStore.startTimer();
- }
- }
- }
- // try to parse natural language like "1h 30m"
- else if (time && time > 1) {
- const newStartDate = dayjs().subtract(time, 's');
- currentTimeEntry.value.start = newStartDate.utc().format();
- if (currentTimeEntry.value.id !== '') {
- currentTimeEntryStore.updateTimer();
- } else {
- currentTimeEntryStore.startTimer();
- }
- }
- // fallback to minutes if just a number is given
- now.value = dayjs().utc();
- temporaryCustomTimerEntry.value = '';
- startLiveTimer();
-}
-
-function isNumeric(value: string) {
- return /^-?\d+$/.test(value);
-}
-
-const HHMMtimeRegex = /^([0-9]{1,2}):([0-5]?[0-9])$/;
-
-function isHHMM(value: string): boolean {
- return HHMMtimeRegex.test(value);
-}
-
-function parseHHMM(value: string): string[] | null {
- return value.match(HHMMtimeRegex);
-}
-
function startTimerIfNotActive() {
if (!isActive.value) {
onToggleButtonPress(true);
}
}
-function onTimeEntryEnterPress() {
- updateTimerAndStartLiveTimerUpdate();
- const activeElement = document.activeElement as HTMLElement;
- activeElement?.blur();
-}
-
const isRunningInDifferentOrganization = computed(() => {
return (
currentTimeEntry.value.organization_id &&
@@ -219,15 +127,7 @@ function switchToTimeEntryOrganization() {
">
-
+