|
23 | 23 | </div> |
24 | 24 | </template> |
25 | 25 |
|
26 | | -<script> |
27 | | -import { defineComponent, inject, ref, computed } from 'vue' |
| 26 | +<script setup> |
| 27 | +import { ref, computed } from 'vue' |
28 | 28 | import { DateTime, Settings } from 'luxon' |
29 | 29 | import { eventClass, isAlldayTag } from '@/helpers/calendar' |
30 | | -
|
31 | 30 | import AlldayEvent from './Events/AlldayEvent' |
32 | 31 | import DefaultEvent from './Events/DefaultEvent' |
33 | 32 | import DutyEvent from './Events/DutyEvent' |
34 | 33 | import RotationEvent from './Events/RotationEvent' |
| 34 | +import { usePlanning } from '@/store' |
35 | 35 |
|
36 | 36 | const TIMEZONE = 'Europe/Paris' |
37 | 37 | Settings.defaultLocale = 'fr' |
38 | 38 | Settings.defaultZoneName = TIMEZONE |
39 | 39 |
|
40 | | -export default defineComponent({ |
41 | | - name: 'CalendarDay', |
42 | | - props: ['day'], |
43 | | - setup(props) { |
44 | | - const zone = ref('Europe/Paris') |
45 | | - const locale = ref('fr') |
46 | | - const datasource = inject('datasource') |
| 40 | +// eslint-disable-next-line no-undef |
| 41 | +const props = defineProps(['day']) |
47 | 42 |
|
48 | | - // TODO : implement global state |
49 | | - const globalState = { |
50 | | - userId: 'IEN' |
51 | | - } |
| 43 | +const zone = ref(TIMEZONE) |
| 44 | +const locale = ref('fr') |
52 | 45 |
|
53 | | - const state = computed(() => { |
54 | | - const dayState = datasource.getDay(globalState.userId, props.day.iso) |
55 | | - return ( |
56 | | - dayState || { |
57 | | - date: props.day.iso, |
58 | | - tags: [], |
59 | | - hints: [], |
60 | | - allday: false, |
61 | | - label: '', |
62 | | - events: [] |
63 | | - } |
64 | | - ) |
65 | | - }) |
| 46 | +const planning = usePlanning() |
66 | 47 |
|
67 | | - function getTime(ts) { |
68 | | - return DateTime.fromMillis(ts, { |
69 | | - zone: zone.value, |
70 | | - locale: locale.value |
71 | | - }).toFormat('HH:mm') |
72 | | - } |
73 | 48 |
|
74 | | - function eventComponent(evt) { |
75 | | - if (isAlldayTag(evt.tag)) { |
76 | | - return AlldayEvent |
77 | | - } |
78 | | - if (evt.tag === 'rotation') { |
79 | | - return RotationEvent |
80 | | - } |
81 | | - if (evt.events) { |
82 | | - return DutyEvent |
83 | | - } |
84 | | - return DefaultEvent |
| 49 | +const state = computed(() => { |
| 50 | + const dayState = planning.getDay(props.day.iso) |
| 51 | + return ( |
| 52 | + dayState || { |
| 53 | + date: props.day.iso, |
| 54 | + tags: [], |
| 55 | + hints: [], |
| 56 | + allday: false, |
| 57 | + label: '', |
| 58 | + events: [] |
85 | 59 | } |
| 60 | + ) |
| 61 | +}) |
86 | 62 |
|
87 | | - return { |
88 | | - state, |
89 | | - eventComponent, |
90 | | - eventClass, |
91 | | - getTime |
92 | | - } |
| 63 | +function eventComponent(evt) { |
| 64 | + if (isAlldayTag(evt.tag)) { |
| 65 | + return AlldayEvent |
93 | 66 | } |
94 | | -}) |
| 67 | + if (evt.tag === 'rotation') { |
| 68 | + return RotationEvent |
| 69 | + } |
| 70 | + if (evt.events) { |
| 71 | + return DutyEvent |
| 72 | + } |
| 73 | + return DefaultEvent |
| 74 | +} |
95 | 75 | </script> |
96 | 76 |
|
97 | 77 | <style lang="scss"> |
|
0 commit comments