Skip to content

Commit

Permalink
🔨 Type calendar store
Browse files Browse the repository at this point in the history
  • Loading branch information
devmount committed Jun 21, 2024
1 parent c02a29d commit 9a220e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions frontend/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ export type Appointment = {
calendar_color: string;
active: boolean;
};

export type Calendar = {
id: number;
connected: boolean;
title: string;
color: string;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Calendar } from '@/models';
import { UseFetchReturn } from '@vueuse/core';
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';

Expand All @@ -7,17 +9,17 @@ export const useCalendarStore = defineStore('calendars', () => {
const isLoaded = ref(false);

// Data
const calendars = ref([]);
const unconnectedCalendars = computed(() => calendars.value.filter((cal) => !cal.connected));
const connectedCalendars = computed(() => calendars.value.filter((cal) => cal.connected));
const calendars = ref<Calendar[]>([]);
const unconnectedCalendars = computed((): Calendar[] => calendars.value.filter((cal) => !cal.connected));
const connectedCalendars = computed((): Calendar[] => calendars.value.filter((cal) => cal.connected));

const hasConnectedCalendars = computed(() => connectedCalendars.value.length > 0);

/**
* Get all calendars for current user
* @param {function} call preconfigured API fetch function
*/
const fetch = async (call) => {
const fetch = async (call: (url: string) => UseFetchReturn<Calendar[]> & PromiseLike<UseFetchReturn<Calendar[]>>) => {
if (isLoaded.value) {
return;
}
Expand Down

0 comments on commit 9a220e5

Please sign in to comment.