|
1 | 1 | <script setup lang="ts"> |
2 | | -import { computed, inject, onMounted, ref } from 'vue'; |
3 | | -import { callKey, refreshKey } from '@/keys'; |
| 2 | +import { computed, inject, ref } from 'vue'; |
| 3 | +import { refreshKey } from '@/keys'; |
4 | 4 | import { PhArrowClockwise } from '@phosphor-icons/vue'; |
5 | 5 | import { storeToRefs } from 'pinia'; |
6 | | -import { useTimeAgoIntl } from '@vueuse/core'; |
| 6 | +import { formatTimeAgoIntl, useNow } from '@vueuse/core'; |
7 | 7 | import { useI18n } from 'vue-i18n'; |
8 | 8 | import { useCalendarStore } from '@/stores/calendar-store'; |
9 | | -import { createScheduleStore } from '@/stores/schedule-store'; |
| 9 | +import { useScheduleStore } from '@/stores/schedule-store'; |
10 | 10 | import { useUserStore } from '@/stores/user-store'; |
11 | 11 |
|
12 | 12 | const refresh = inject(refreshKey); |
13 | | -const call = inject(callKey); |
14 | 13 | const { t } = useI18n(); |
15 | 14 |
|
16 | | -const loading = ref(false); |
17 | | -const lastRefreshedTime = ref(Date.now()); |
18 | | -
|
19 | 15 | const calendarStore = useCalendarStore(); |
20 | 16 | const userStore = useUserStore(); |
21 | | -const scheduleStore = createScheduleStore(call); |
| 17 | +const scheduleStore = useScheduleStore(); |
| 18 | +
|
22 | 19 | const { firstSchedule } = storeToRefs(scheduleStore); |
23 | 20 |
|
| 21 | +const loading = ref(false); |
| 22 | +const lastRefreshedTime = ref(new Date()); |
| 23 | +
|
| 24 | +const { now } = useNow({ interval: 30000, controls: true }); |
| 25 | +const timeAgo = computed(() => |
| 26 | + formatTimeAgoIntl(lastRefreshedTime.value, { locale: userStore?.data?.settings?.language }, now.value) |
| 27 | +); |
| 28 | +
|
24 | 29 | const scheduleCalendar = computed(() => { |
25 | 30 | return calendarStore.calendarById(firstSchedule.value?.calendar_id) |
26 | 31 | }) |
27 | 32 |
|
28 | | -const timeAgo = useTimeAgoIntl(lastRefreshedTime, { locale: userStore.data.settings.language }); |
29 | | -
|
30 | 33 | async function onSyncCalendarButtonClicked() { |
31 | 34 | loading.value = true; |
32 | 35 |
|
33 | 36 | await calendarStore.syncCalendars(); |
34 | | - await refreshData(); |
35 | | - lastRefreshedTime.value = Date.now(); |
| 37 | + await refresh(); |
| 38 | +
|
| 39 | + const currentTime = new Date(); |
| 40 | + lastRefreshedTime.value = currentTime; |
| 41 | + now.value = currentTime; |
36 | 42 |
|
37 | 43 | loading.value = false; |
38 | 44 | } |
39 | | -
|
40 | | -async function refreshData() { |
41 | | - calendarStore.$reset(); |
42 | | - await refresh(); |
43 | | -}; |
44 | | -
|
45 | | -onMounted(async () => { |
46 | | - await scheduleStore.fetch(); |
47 | | -}) |
48 | 45 | </script> |
49 | 46 |
|
50 | 47 | <template> |
|
0 commit comments