refac
This commit is contained in:
@@ -5,7 +5,7 @@ export type CalendarModel = {
|
||||
user_id: string;
|
||||
name: string;
|
||||
color: string | null;
|
||||
is_system: boolean;
|
||||
is_default: boolean;
|
||||
data: Record<string, any> | null;
|
||||
meta: Record<string, any> | null;
|
||||
access_grants: any[];
|
||||
@@ -188,6 +188,37 @@ export const deleteCalendar = async (token: string, calendarId: string): Promise
|
||||
return res?.status ?? false;
|
||||
};
|
||||
|
||||
export const setDefaultCalendar = async (
|
||||
token: string,
|
||||
calendarId: string
|
||||
): Promise<CalendarModel> => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/calendars/${calendarId}/default`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err.detail;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
// ── Events ─────────────────────────────────
|
||||
|
||||
export const getCalendarEvents = async (
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
showEventModal = true;
|
||||
}
|
||||
|
||||
$: defaultCalendarId = calendars.find((c) => !c.is_system || c.name === 'Personal')?.id || calendars[0]?.id || '';
|
||||
$: defaultCalendarId = calendars.find((c) => c.is_default)?.id || calendars[0]?.id || '';
|
||||
|
||||
onMount(async () => {
|
||||
await loadCalendars();
|
||||
|
||||
Reference in New Issue
Block a user