useCalendarStore.js
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export const useCalendarStore = defineStore('calendar', {
// arrow function recommended for full type inference
state: () => ({
availableCalendars: [
{
color: 'error',
label: 'Personal',
},
{
color: 'primary',
label: 'Business',
},
{
color: 'warning',
label: 'Family',
},
{
color: 'success',
label: 'Holiday',
},
{
color: 'info',
label: 'ETC',
},
],
selectedCalendars: ['Personal', 'Business', 'Family', 'Holiday', 'ETC'],
}),
actions: {
async fetchEvents() {
const { data, error } = await useApi(createUrl('/apps/calendar', {
query: {
calendars: this.selectedCalendars,
},
}))
if (error.value)
return error.value
return data.value
},
async addEvent(event) {
await $api('/apps/calendar', {
method: 'POST',
body: event,
})
},
async updateEvent(event) {
return await $api(`/apps/calendar/${event.id}`, {
method: 'PUT',
body: event,
})
},
async removeEvent(eventId) {
return await $api(`/apps/calendar/${eventId}`, {
method: 'DELETE',
})
},
},
})