Fix creating and deleting calendars
This fixes the creation and deletion of calendars to include a color and the proper chosen name.
This commit is contained in:
@@ -120,6 +120,7 @@ export class CalendarModel {
|
||||
static async create(
|
||||
userId: string,
|
||||
name: string,
|
||||
color: string,
|
||||
): Promise<void> {
|
||||
const calendarId = crypto.randomUUID();
|
||||
const calendarUrl = `${calendarConfig.calDavUrl}/${userId}/${calendarId}/`;
|
||||
@@ -129,7 +130,8 @@ export class CalendarModel {
|
||||
await client.makeCalendar({
|
||||
url: calendarUrl,
|
||||
props: {
|
||||
displayName: name,
|
||||
displayname: name,
|
||||
calendarColor: color,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -163,8 +165,10 @@ export class CalendarModel {
|
||||
|
||||
static async delete(
|
||||
userId: string,
|
||||
calendarUrl: string,
|
||||
calendarId: string,
|
||||
): Promise<void> {
|
||||
const calendarUrl = `${calendarConfig.calDavUrl}/${userId}/${calendarId}/`;
|
||||
|
||||
const client = await getClient(userId);
|
||||
|
||||
await client.deleteObject({
|
||||
|
||||
@@ -21,6 +21,7 @@ export const CALENDAR_COLOR_OPTIONS = [
|
||||
'bg-fuchsia-700',
|
||||
'bg-pink-800',
|
||||
'bg-rose-700',
|
||||
'bg-gray-700',
|
||||
] as const;
|
||||
|
||||
const CALENDAR_COLOR_OPTIONS_HEX = [
|
||||
@@ -44,9 +45,12 @@ const CALENDAR_COLOR_OPTIONS_HEX = [
|
||||
'#9D21B1',
|
||||
'#9C174D',
|
||||
'#BC133D',
|
||||
'#384354',
|
||||
] as const;
|
||||
|
||||
export function getColorAsHex(calendarColor: string) {
|
||||
export function getColorAsHex(
|
||||
calendarColor: (typeof CALENDAR_COLOR_OPTIONS)[number],
|
||||
): (typeof CALENDAR_COLOR_OPTIONS_HEX)[number] {
|
||||
const colorIndex = CALENDAR_COLOR_OPTIONS.findIndex((color) => color === calendarColor);
|
||||
|
||||
return CALENDAR_COLOR_OPTIONS_HEX[colorIndex] || '#384354';
|
||||
|
||||
@@ -3,6 +3,7 @@ import { assertMatch } from 'std/assert/assert_match.ts';
|
||||
|
||||
import { Calendar, CalendarEvent } from '/lib/models/calendar.ts';
|
||||
import {
|
||||
CALENDAR_COLOR_OPTIONS,
|
||||
convertRRuleToWords,
|
||||
generateVCalendar,
|
||||
generateVEvent,
|
||||
@@ -29,7 +30,7 @@ Deno.test('that getColorAsHex works', () => {
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
const output = getColorAsHex(test.input);
|
||||
const output = getColorAsHex(test.input as typeof CALENDAR_COLOR_OPTIONS[number]);
|
||||
assertEquals(output, test.expected);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user