diff --git a/.prettierrc.json b/.prettierrc.json index 66e2335..29b6305 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -4,5 +4,5 @@ "tabWidth": 2, "singleQuote": true, "printWidth": 100, - "trailingComma": "none" + "trailingComma": "all" } \ No newline at end of file diff --git a/src/assets/main.css b/src/assets/main.css index bd6213e..b5c61c9 100644 --- a/src/assets/main.css +++ b/src/assets/main.css @@ -1,3 +1,3 @@ @tailwind base; @tailwind components; -@tailwind utilities; \ No newline at end of file +@tailwind utilities; diff --git a/src/components/DaySummary.vue b/src/components/DaySummary.vue index e07f75f..c453966 100644 --- a/src/components/DaySummary.vue +++ b/src/components/DaySummary.vue @@ -4,13 +4,14 @@ import { format, formatDuration } from 'date-fns' import { de } from 'date-fns/locale' import { computed } from 'vue' import { getRatio } from '../lib/date-fns/getRatio' +import HoursProgress from './HoursProgress.vue' const timesStore = useTimesStore() const lessThan8Hours = computed(() => (timesStore.workTimeOfSelectedDay.hours ?? 0) < 8) const remainingLabel = computed(() => - lessThan8Hours.value ? '8 Stunden erreicht in' : 'Überstunden' + lessThan8Hours.value ? '8 Stunden erreicht in' : 'Überstunden', ) @@ -22,7 +23,7 @@ const remainingLabel = computed(() => {{ formatDuration(timesStore.workTimeOfSelectedDay, { format: ['hours', 'minutes'], - locale: de + locale: de, }) || '-' }} @@ -34,7 +35,7 @@ const remainingLabel = computed(() => {{ formatDuration(timesStore.remainingWorkTimeOfSelectedDay, { format: ['hours', 'minutes'], - locale: de + locale: de, }) }} @@ -51,22 +52,8 @@ const remainingLabel = computed(() => -
-
-
- -
- - +
+
@@ -75,7 +62,7 @@ const remainingLabel = computed(() => {{ formatDuration(timesStore.breakTimeOfSelectedDay, { format: ['hours', 'minutes'], - locale: de + locale: de, }) || '-' }}
diff --git a/src/components/DaysListItem.vue b/src/components/DaysListItem.vue index 2af7c63..b450801 100644 --- a/src/components/DaysListItem.vue +++ b/src/components/DaysListItem.vue @@ -12,7 +12,7 @@ const timesStore = useTimesStore() class="px-3 py-2 cursor-default text-center rounded select-none" :class="{ 'hover:bg-gray-200': !isSameDay(timesStore.selectedDay, day), - 'bg-gray-300': isSameDay(timesStore.selectedDay, day) + 'bg-gray-300': isSameDay(timesStore.selectedDay, day), }" @click="timesStore.setSelectedDay(day)" > diff --git a/src/components/HoursProgress.vue b/src/components/HoursProgress.vue new file mode 100644 index 0000000..ef56941 --- /dev/null +++ b/src/components/HoursProgress.vue @@ -0,0 +1,32 @@ + + + diff --git a/src/components/ToolbarButton.vue b/src/components/ToolbarButton.vue index f3975b2..3d9fe2b 100644 --- a/src/components/ToolbarButton.vue +++ b/src/components/ToolbarButton.vue @@ -1,5 +1,7 @@ \ No newline at end of file + diff --git a/src/components/UiStack.vue b/src/components/UiStack.vue index 2da1e4f..559b81c 100644 --- a/src/components/UiStack.vue +++ b/src/components/UiStack.vue @@ -2,4 +2,4 @@
- \ No newline at end of file + diff --git a/src/lib/date-fns/getRatio.ts b/src/lib/date-fns/getRatio.ts index 2f9538f..1198a18 100644 --- a/src/lib/date-fns/getRatio.ts +++ b/src/lib/date-fns/getRatio.ts @@ -4,5 +4,5 @@ export function getRatio(duration: Duration, compareDuration: Duration): number const baseDate = new Date(0) const compareDate = add(baseDate, compareDuration) const date = add(baseDate, duration) - return 1 / compareDate.getTime() * date.getTime() + return (1 / compareDate.getTime()) * date.getTime() } diff --git a/src/lib/date/sortDates.ts b/src/lib/date/sortDates.ts index 2ea7492..6356357 100644 --- a/src/lib/date/sortDates.ts +++ b/src/lib/date/sortDates.ts @@ -1,3 +1,8 @@ -export function sortDates(dateA: Date, dateB: Date): number { - return dateB.getTime() - dateA.getTime() -} \ No newline at end of file +export function sortDates(reverse = false): (dateA: Date, dateB: Date) => number { + return (dateA, dateB) => { + if (reverse) { + return dateA.getTime() - dateB.getTime() + } + return dateB.getTime() - dateA.getTime() + } +} diff --git a/src/stores/times.ts b/src/stores/times.ts index 1deb736..11971fe 100644 --- a/src/stores/times.ts +++ b/src/stores/times.ts @@ -20,7 +20,7 @@ export const useTimesStore = defineStore('times', () => { watchEffect(() => { const serializedTimestamps = JSON.stringify( - timestamps.value.map((timestamp) => timestamp.getTime()) + timestamps.value.map((timestamp) => timestamp.getTime()), ) localStorage.setItem(timestampsStorageKey, serializedTimestamps) }) @@ -34,9 +34,13 @@ export const useTimesStore = defineStore('times', () => { } } - days.sort(sortDates) + days.sort(sortDates()) - const today = new Date(currentTime.value.getFullYear(), currentTime.value.getMonth(), currentTime.value.getDate()) + const today = new Date( + currentTime.value.getFullYear(), + currentTime.value.getMonth(), + currentTime.value.getDate(), + ) if (!isSameDay(days[0], today)) { days.unshift(today) @@ -52,7 +56,9 @@ export const useTimesStore = defineStore('times', () => { }) const timestampsOfSelectedDay = computed((): Date[] => { - return timestamps.value.filter((timestamp) => isSameDay(timestamp, selectedDay.value)) + const result = timestamps.value.filter((timestamp) => isSameDay(timestamp, selectedDay.value)) + result.sort(sortDates(true)) + return result }) const workTimeOfSelectedDay = computed((): Duration => { @@ -63,7 +69,7 @@ export const useTimesStore = defineStore('times', () => { list.forEach((timestamp, index) => { if (index % 2 === 0) return workTimeDurations.push( - intervalToDuration({ start: timestampsOfSelectedDay.value[index - 1], end: timestamp }) + intervalToDuration({ start: timestampsOfSelectedDay.value[index - 1], end: timestamp }), ) }) @@ -81,7 +87,7 @@ export const useTimesStore = defineStore('times', () => { if (index % 2 === 1 || index === 0) return breakTimeDurations.push( - intervalToDuration({ start: timestampsOfSelectedDay.value[index - 1], end: timestamp }) + intervalToDuration({ start: timestampsOfSelectedDay.value[index - 1], end: timestamp }), ) }) @@ -112,7 +118,6 @@ export const useTimesStore = defineStore('times', () => { }, addTime(time: Date) { timestamps.value.push(time) - timestamps.value.sort(sortDates) }, addCurrentTime() { this.addTime(new Date())