This commit is contained in:
Timothy Jaeryang Baek committed 2026-12-02 20:05:04 +04:00
1 parent 891c8a0473
commit bf182c104f
4 files changed
+384 -418

No files matched your search

+217 -139
View File
@@ -16,15 +16,20 @@
type CalendarEventModel
} from '$lib/apis/calendar';
import CalendarView from '$lib/components/calendar/CalendarView.svelte';
import CalendarSidebar from '$lib/components/calendar/CalendarSidebar.svelte';
import CalendarMiniMonth from '$lib/components/calendar/CalendarMiniMonth.svelte';
import CalendarEventModal from '$lib/components/calendar/CalendarEventModal.svelte';
import CreateCalendarModal from '$lib/components/calendar/CreateCalendarModal.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import SidebarIcon from '$lib/components/icons/Sidebar.svelte';
import Select from '$lib/components/common/Select.svelte';
import Dropdown from '$lib/components/common/Dropdown.svelte';
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import DropdownSub from '$lib/components/common/DropdownSub.svelte';
import Check from '$lib/components/icons/Check.svelte';
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
import Plus from '$lib/components/icons/Plus.svelte';
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
@@ -43,6 +48,13 @@
let defaultStartAt: number | null = null;
let showCreateCalendarModal = false;
let editCalendar: CalendarModel | null = null;
let showMiniMonth = false;
const menuLabel = 'px-2 pt-1.5 pb-0.5 text-xs text-base-400 dark:text-base-500';
const iconButton =
'relative flex size-6.5 shrink-0 items-center justify-center rounded-full border border-base-100 bg-base-50/60 text-base-500 transition-colors hover:bg-base-100 hover:text-base-900 aria-expanded:bg-base-100 aria-expanded:text-base-900 dark:border-base-850 dark:bg-base-850/50 dark:text-base-400 dark:hover:bg-base-850 dark:hover:text-base-0 dark:aria-expanded:bg-base-850 dark:aria-expanded:text-base-0';
const pillButton =
'flex h-6.5 shrink-0 items-center gap-1 rounded-full border border-base-100 bg-base-50/60 px-2.5 text-xs text-base-500 transition-colors hover:bg-base-100 hover:text-base-900 aria-expanded:bg-base-100 aria-expanded:text-base-900 dark:border-base-850 dark:bg-base-850/50 dark:text-base-400 dark:hover:bg-base-850 dark:hover:text-base-0 dark:aria-expanded:bg-base-850 dark:aria-expanded:text-base-0';
const MONTH_NAMES = [
'January',
@@ -182,6 +194,7 @@
}
async function handleDateSelect(date: Date) {
showMiniMonth = false;
currentDate = date;
view = 'day';
await tick();
@@ -225,6 +238,9 @@
handleNavigate();
}
$: hiddenCalendars = calendars.some((c) => !visibleCalendarIds.has(c.id));
$: editableCalendars = calendars.filter((c) => !c.is_system);
$: defaultCalendarId = calendars.find((c) => c.is_default)?.id || calendars[0]?.id || '';
$: headerText =
@@ -302,159 +318,221 @@
bind:show={showCreateCalendarModal}
calendar={editCalendar}
on:created={handleCalendarCreated}
on:delete={(e) => handleDeleteCalendar(e.detail)}
/>
<div
class="@container flex flex-col w-full h-full max-h-full transition-width duration-200 ease-in-out {$showSidebar &&
class="flex flex-col w-full h-full max-h-full transition-width duration-200 ease-in-out {$showSidebar &&
!pageTab
? 'md:max-w-[calc(100%-var(--sidebar-width))]'
: ''} max-w-full"
>
{#if loaded}
<!-- Top Navbar — spans above sidebar and calendar -->
<nav class="px-1.5 pb-2 md:px-3 drag-region select-none shrink-0">
<div class="flex items-center gap-0.5 md:gap-1">
{#if $mobile && !pageTab}
<div class="{$showSidebar ? 'md:hidden' : ''} flex flex-none items-center self-start">
<Tooltip
content={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')}
interactive={true}
>
<button
id="sidebar-toggle-button"
class="cursor-pointer flex rounded-lg hover:bg-base-100 dark:hover:bg-base-850 transition"
aria-label={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')}
on:click={() => showSidebar.set(!$showSidebar)}
>
<div class="self-center p-1.5">
<SidebarIcon className="size-4" />
</div>
</button>
</Tooltip>
</div>
{/if}
<div class="flex w-full items-center">
<div class="flex items-center gap-0.5 py-1">
<span class="min-w-fit px-1 text-sm select-none">{headerText}</span>
<!-- Same row and circle buttons as the list pages (Automations, Workspace). -->
<nav class="flex h-8 shrink-0 items-center gap-1 px-2.5 drag-region select-none">
{#if $mobile && !pageTab}
<div class="{$showSidebar ? 'md:hidden' : ''} flex flex-none items-center">
<Tooltip content={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')}>
<button
class="p-1 rounded-lg hover:bg-base-50 dark:hover:bg-base-850 transition"
on:click={() => navigateCalendar(-1)}
aria-label={$i18n.t('Previous')}
id="sidebar-toggle-button"
class="flex size-7 items-center justify-center text-base-400 transition"
aria-label={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')}
on:click={() => showSidebar.set(!$showSidebar)}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-3.5 text-base-400"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5 8.25 12l7.5-7.5"
/></svg
>
<SidebarIcon className="size-4" />
</button>
<button
class="p-1 rounded-lg hover:bg-base-50 dark:hover:bg-base-850 transition"
on:click={() => navigateCalendar(1)}
aria-label={$i18n.t('Next')}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-3.5 text-base-400"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="m8.25 4.5 7.5 7.5-7.5 7.5"
/></svg
>
</button>
</div>
<div class="ml-auto flex items-center gap-1">
<button
class="hidden sm:inline text-xs px-2 py-1 rounded-lg hover:bg-base-50 dark:hover:bg-base-850 transition text-base-500 hover:text-base-700 dark:hover:text-base-0"
on:click={goToToday}
>
{$i18n.t('Today')}
</button>
<Select
bind:value={view}
items={[
{ value: 'day', label: $i18n.t('Day') },
{ value: 'week', label: $i18n.t('Week') },
{ value: 'month', label: $i18n.t('Month') }
]}
onChange={() => handleNavigate()}
triggerClass="relative flex items-center gap-1 px-2 py-1 rounded-lg text-xs text-base-500 transition hover:bg-base-50 hover:text-base-700 dark:hover:bg-base-850 dark:hover:text-base-0"
contentClass="rounded-xl w-28 p-1 border border-base-100 dark:border-base-800 bg-base-0 dark:bg-base-850 dark:text-base-0 shadow-lg"
align="end"
>
<svelte:fragment slot="trigger" let:selectedLabel>
<span
class="inline-flex h-input px-0.5 outline-hidden bg-transparent truncate line-clamp-1"
>
{selectedLabel}
</span>
<ChevronDown className="size-3.5" strokeWidth="2.5" />
</svelte:fragment>
<svelte:fragment slot="item" let:item let:selected>
{item.label}
<div class="ml-auto {selected ? '' : 'invisible'}">
<Check />
</div>
</svelte:fragment>
</Select>
<button
class="ml-1 rounded-lg bg-base-50 px-2.5 py-1 text-xs text-base-900 transition ring-1 ring-base-200 hover:bg-base-100 dark:bg-base-850 dark:text-base-100 dark:ring-base-800 dark:hover:bg-base-800"
on:click={handleNewEvent}
>
{$i18n.t('Create')}
</button>
</div>
</Tooltip>
</div>
{/if}
<div class="flex min-w-0 flex-1 items-center gap-0.5">
<Dropdown bind:show={showMiniMonth} align="start" sideOffset={6}>
<button
type="button"
class="flex min-w-0 items-center gap-1 rounded-lg px-1 py-0.5 text-sm transition hover:bg-base-50 dark:hover:bg-base-850"
>
<span class="truncate">{headerText}</span>
<ChevronDown className="size-3 shrink-0 text-base-400" strokeWidth="2.5" />
</button>
<div
slot="content"
class="w-52 rounded-xl border border-base-100 bg-base-0 p-1.5 shadow-lg dark:border-base-800 dark:bg-base-850 dark:text-base-0"
>
<CalendarMiniMonth {currentDate} onDateSelect={handleDateSelect} />
</div>
</Dropdown>
<button
class="shrink-0 p-1 rounded-lg hover:bg-base-50 dark:hover:bg-base-850 transition"
on:click={() => navigateCalendar(-1)}
aria-label={$i18n.t('Previous')}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-3.5 text-base-400"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5 8.25 12l7.5-7.5"
/></svg
>
</button>
<button
class="shrink-0 p-1 rounded-lg hover:bg-base-50 dark:hover:bg-base-850 transition"
on:click={() => navigateCalendar(1)}
aria-label={$i18n.t('Next')}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="size-3.5 text-base-400"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="m8.25 4.5 7.5 7.5-7.5 7.5"
/></svg
>
</button>
</div>
<div class="flex shrink-0 items-center gap-1">
<button type="button" class="hidden sm:flex {pillButton}" on:click={goToToday}>
{$i18n.t('Today')}
</button>
<Select
bind:value={view}
items={[
{ value: 'day', label: $i18n.t('Day') },
{ value: 'week', label: $i18n.t('Week') },
{ value: 'month', label: $i18n.t('Month') }
]}
onChange={() => handleNavigate()}
triggerClass={pillButton}
contentClass="rounded-xl w-28 p-1 border border-base-100 dark:border-base-800 bg-base-0 dark:bg-base-850 dark:text-base-0 shadow-lg"
align="end"
>
<svelte:fragment slot="trigger" let:selectedLabel>
<span class="truncate">{selectedLabel}</span>
<ChevronDown className="size-3 shrink-0" strokeWidth="2.5" />
</svelte:fragment>
<svelte:fragment slot="item" let:item let:selected>
{item.label}
<div class="ml-auto {selected ? '' : 'invisible'}">
<Check />
</div>
</svelte:fragment>
</Select>
<!-- Which calendars show is a filter, so it lives behind the same filter circle. -->
<Dropdown align="end">
<button
type="button"
class="{iconButton} {hiddenCalendars ? 'text-base-800 dark:text-base-100' : ''}"
aria-label={$i18n.t('Calendars')}
title={$i18n.t('Calendars')}
>
<svg
class="size-3.75"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
aria-hidden="true"><path d="M2.5 4h11M4.5 8h7M6.5 12h3" /></svg
>
{#if hiddenCalendars}
<span
class="absolute -right-0.5 -top-0.5 size-1.5 rounded-full bg-base-800 dark:bg-base-100"
></span>
{/if}
</button>
<DropdownMenu slot="content" className="w-52">
<div class={menuLabel}>{$i18n.t('Calendars')}</div>
{#each calendars as cal (cal.id)}
<button
type="button"
role="menuitemcheckbox"
aria-checked={visibleCalendarIds.has(cal.id)}
on:click={() => toggleCalendar(cal.id)}
>
<span
class="size-2.5 shrink-0 rounded-full"
style="background-color: {cal.color || '#3b82f6'};"
></span>
<span class="min-w-0 flex-1 truncate text-left">{cal.name}</span>
{#if visibleCalendarIds.has(cal.id)}<Check className="size-3! shrink-0" />{/if}
</button>
{/each}
<hr class="border-base-50/30 dark:border-base-800/30" />
{#if editableCalendars.length > 0}
<DropdownSub
contentClass="select-none z-50 max-h-80 overflow-y-auto"
maxWidth={320}
sideOffset={6}
>
<button
slot="trigger"
type="button"
class="flex h-[1.6875rem] w-full cursor-pointer select-none items-center gap-2 rounded-xl px-2 text-left text-[0.8125rem] outline-hidden"
>
<span class="min-w-0 flex-1 truncate text-left">{$i18n.t('Edit')}</span>
<ChevronRight className="size-3.5 shrink-0 text-base-400 rtl:rotate-180" />
</button>
{#each editableCalendars as cal (cal.id)}
<button type="button" on:click={() => handleEditCalendar(cal)}>
<span
class="size-2.5 shrink-0 rounded-full"
style="background-color: {cal.color || '#3b82f6'};"
></span>
<span class="min-w-0 flex-1 truncate text-left">{cal.name}</span>
</button>
{/each}
</DropdownSub>
{/if}
<button type="button" on:click={handleCreateCalendar}>
<Plus className="size-3.5" strokeWidth="2" />
<span class="flex-1 text-left">{$i18n.t('New calendar')}</span>
</button>
</DropdownMenu>
</Dropdown>
<button
type="button"
class={iconButton}
aria-label={$i18n.t('Create')}
title={$i18n.t('Create')}
on:click={handleNewEvent}
>
<Plus className="size-3.5" strokeWidth="2" />
</button>
</div>
</nav>
<div class="flex flex-1 min-h-0">
<!-- Sidebar -->
<div class="hidden @3xl:flex flex-col w-56 shrink-0 pr-1.5 pl-3 overflow-y-auto">
<CalendarSidebar
{calendars}
{visibleCalendarIds}
{currentDate}
onToggle={toggleCalendar}
onCreateCalendar={handleCreateCalendar}
onEditCalendar={handleEditCalendar}
onDeleteCalendar={handleDeleteCalendar}
onDateSelect={handleDateSelect}
/>
</div>
<!-- Calendar -->
<div class="flex-1 flex flex-col min-h-0">
<CalendarView
bind:this={calendarView}
{events}
{calendars}
{visibleCalendarIds}
bind:view
bind:currentDate
on:createEvent={handleCreateEvent}
on:eventClick={handleEventClick}
on:moveEvent={handleMoveEvent}
onNavigate={handleNavigate}
/>
</div>
<div class="flex flex-1 flex-col min-h-0">
<CalendarView
bind:this={calendarView}
{events}
{calendars}
{visibleCalendarIds}
bind:view
bind:currentDate
on:createEvent={handleCreateEvent}
on:eventClick={handleEventClick}
on:moveEvent={handleMoveEvent}
onNavigate={handleNavigate}
/>
</div>
{:else}
<div class="w-full h-full flex justify-center items-center">
@@ -0,0 +1,139 @@
<script lang="ts">
import { getContext } from 'svelte';
import { settings } from '$lib/stores';
const i18n = getContext('i18n');
export let currentDate: Date = new Date();
export let onDateSelect: (date: Date) => void = () => {};
$: miniMonth = currentDate.getMonth();
$: miniYear = currentDate.getFullYear();
$: miniMonthStart = new Date(miniYear, miniMonth, 1);
$: miniCalStart = (() => {
const d = new Date(miniMonthStart);
d.setDate(d.getDate() - d.getDay());
return d;
})();
$: miniDays = (() => {
const days: Date[] = [];
const d = new Date(miniCalStart);
for (let i = 0; i < 42; i++) {
days.push(new Date(d));
d.setDate(d.getDate() + 1);
}
return days;
})();
$: miniMonthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
function isToday(d: Date): boolean {
return d.toDateString() === new Date().toDateString();
}
$: isSelected = (d: Date): boolean => d.toDateString() === currentDate.toDateString();
function navigateMini(delta: number) {
if (miniMonth + delta > 11) {
miniMonth = 0;
miniYear++;
} else if (miniMonth + delta < 0) {
miniMonth = 11;
miniYear--;
} else {
miniMonth += delta;
}
}
</script>
<div>
<div class="flex items-center justify-between px-1 mb-1.5 mt-1.5">
<div class="text-[0.6875rem] font-normal">{miniMonthNames[miniMonth]} {miniYear}</div>
<div class="flex items-center gap-0.5">
<button
class="{($settings?.highContrastMode ?? false)
? 'p-1.5'
: 'p-0.5'} rounded hover:bg-base-100 dark:hover:bg-base-800 transition"
aria-label={$i18n.t('Previous month')}
on:click={() => navigateMini(-1)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5 8.25 12l7.5-7.5"
/></svg
>
</button>
<button
class="{($settings?.highContrastMode ?? false)
? 'p-1.5'
: 'p-0.5'} rounded hover:bg-base-100 dark:hover:bg-base-800 transition"
aria-label={$i18n.t('Next month')}
on:click={() => navigateMini(1)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="m8.25 4.5 7.5 7.5-7.5 7.5"
/></svg
>
</button>
</div>
</div>
<div
class="grid grid-cols-7 text-center text-[0.5625rem] text-base-400 dark:text-base-500 mb-0.5"
>
{#each ['S', 'M', 'T', 'W', 'T', 'F', 'S'] as d}
<div class="py-0.5">{d}</div>
{/each}
</div>
<div class="grid grid-cols-7 text-center text-[0.625rem]">
{#each miniDays as day}
<button
class="w-6 h-6 flex items-center justify-center rounded-full transition
{day.getMonth() !== miniMonth ? 'text-base-300 dark:text-base-600' : ''}
{isToday(day)
? ($settings?.highContrastMode ?? false)
? 'bg-blue-600 text-white'
: 'bg-blue-500 text-white'
: isSelected(day)
? 'bg-base-100 dark:bg-base-800'
: 'hover:bg-base-50 dark:hover:bg-base-850'}"
on:click={() => onDateSelect(day)}
>
{day.getDate()}
</button>
{/each}
</div>
</div>
@@ -1,277 +0,0 @@
<script lang="ts">
import { withListFocus } from '$lib/utils/listFocus';
import { getContext } from 'svelte';
import { settings } from '$lib/stores';
import type { CalendarModel } from '$lib/apis/calendar';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import Pencil from '$lib/components/icons/Pencil.svelte';
let listElement: HTMLElement;
const i18n = getContext('i18n');
export let calendars: CalendarModel[] = [];
export let visibleCalendarIds: Set<string> = new Set();
export let currentDate: Date = new Date();
export let onToggle: (id: string) => void = () => {};
export let onCreateCalendar: () => void = () => {};
export let onEditCalendar: (cal: CalendarModel) => void = () => {};
export let onDeleteCalendar: (id: string) => void = () => {};
export let onDateSelect: (date: Date) => void = () => {};
// Delete confirmation state
let showDeleteConfirm = false;
let deleteTargetCalendar: CalendarModel | null = null;
function isDeletable(cal: CalendarModel): boolean {
return !cal.is_default && !cal.is_system;
}
function handleDeleteClick(e: MouseEvent, cal: CalendarModel) {
e.stopPropagation();
deleteTargetCalendar = cal;
showDeleteConfirm = true;
}
function confirmDelete() {
if (deleteTargetCalendar) {
const { id } = deleteTargetCalendar;
withListFocus(listElement, id, onDeleteCalendar);
}
deleteTargetCalendar = null;
}
// Mini calendar state
$: miniMonth = currentDate.getMonth();
$: miniYear = currentDate.getFullYear();
$: miniMonthStart = new Date(miniYear, miniMonth, 1);
$: miniCalStart = (() => {
const d = new Date(miniMonthStart);
d.setDate(d.getDate() - d.getDay());
return d;
})();
$: miniDays = (() => {
const days: Date[] = [];
const d = new Date(miniCalStart);
for (let i = 0; i < 42; i++) {
days.push(new Date(d));
d.setDate(d.getDate() + 1);
}
return days;
})();
$: miniMonthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
function isToday(d: Date): boolean {
return d.toDateString() === new Date().toDateString();
}
$: isSelected = (d: Date): boolean => d.toDateString() === currentDate.toDateString();
function navigateMini(delta: number) {
if (miniMonth + delta > 11) {
miniMonth = 0;
miniYear++;
} else if (miniMonth + delta < 0) {
miniMonth = 11;
miniYear--;
} else {
miniMonth += delta;
}
}
</script>
<ConfirmDialog
bind:show={showDeleteConfirm}
title={$i18n.t('Delete Calendar')}
message={$i18n.t(
'This will permanently delete the calendar "{{name}}" and all its events. This action cannot be undone.',
{ name: deleteTargetCalendar?.name ?? '' }
)}
confirmLabel={$i18n.t('Delete')}
onConfirm={confirmDelete}
/>
<div bind:this={listElement} class="flex flex-col gap-4">
<!-- Mini Month Calendar -->
<div>
<div class="flex items-center justify-between px-1 mb-1.5 mt-1.5">
<div class="text-[0.6875rem] font-normal">{miniMonthNames[miniMonth]} {miniYear}</div>
<div class="flex items-center gap-0.5">
<button
class="{($settings?.highContrastMode ?? false)
? 'p-1.5'
: 'p-0.5'} rounded hover:bg-base-100 dark:hover:bg-base-800 transition"
aria-label={$i18n.t('Previous month')}
on:click={() => navigateMini(-1)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5 8.25 12l7.5-7.5"
/></svg
>
</button>
<button
class="{($settings?.highContrastMode ?? false)
? 'p-1.5'
: 'p-0.5'} rounded hover:bg-base-100 dark:hover:bg-base-800 transition"
aria-label={$i18n.t('Next month')}
on:click={() => navigateMini(1)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3"
><path
stroke-linecap="round"
stroke-linejoin="round"
d="m8.25 4.5 7.5 7.5-7.5 7.5"
/></svg
>
</button>
</div>
</div>
<div
class="grid grid-cols-7 text-center text-[0.5625rem] text-base-400 dark:text-base-500 mb-0.5"
>
{#each ['S', 'M', 'T', 'W', 'T', 'F', 'S'] as d}
<div class="py-0.5">{d}</div>
{/each}
</div>
<div class="grid grid-cols-7 text-center text-[0.625rem]">
{#each miniDays as day}
<button
class="w-6 h-6 flex items-center justify-center rounded-full transition
{day.getMonth() !== miniMonth ? 'text-base-300 dark:text-base-600' : ''}
{isToday(day)
? ($settings?.highContrastMode ?? false)
? 'bg-blue-600 text-white'
: 'bg-blue-500 text-white'
: isSelected(day)
? 'bg-base-100 dark:bg-base-800'
: 'hover:bg-base-50 dark:hover:bg-base-850'}"
on:click={() => onDateSelect(day)}
>
{day.getDate()}
</button>
{/each}
</div>
</div>
<!-- Calendar List -->
<div>
<div class="flex items-center justify-between mb-1 px-1">
<div class="text-[0.6875rem] text-base-400 dark:text-base-500 uppercase tracking-wider">
{$i18n.t('Calendars')}
</div>
<button
class="p-0.5 rounded hover:bg-base-100 dark:hover:bg-base-800 transition"
title={$i18n.t('New calendar')}
data-focus-fallback
on:click={onCreateCalendar}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3 text-base-400 dark:text-base-500"
><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg
>
</button>
</div>
{#each calendars as cal (cal.id)}
<div
class="group flex items-center w-full rounded-lg text-xs transition
hover:bg-base-50 dark:hover:bg-base-800/50"
>
<button
class="flex items-center gap-2 px-2 py-1 flex-1 text-left min-w-0"
data-focus-row={cal.id}
on:click={() => onToggle(cal.id)}
>
<span
class="shrink-0 size-2.5 rounded-full transition-opacity"
style="background-color: {cal.color || '#3b82f6'}; opacity: {visibleCalendarIds.has(
cal.id
)
? '1'
: '0.25'};"
></span>
<span
class="truncate flex-1 {visibleCalendarIds.has(cal.id)
? ''
: 'text-base-400 dark:text-base-500'}"
>
{cal.name}
</span>
</button>
{#if !cal.is_system}
<button
type="button"
class="shrink-0 p-0.5 {isDeletable(cal)
? 'mr-0.5'
: 'mr-2'} rounded opacity-0 group-hover:opacity-100 group-focus-within:opacity-100
transition-all duration-150"
title={$i18n.t('Edit')}
aria-label={$i18n.t('Edit')}
on:click|stopPropagation={() => onEditCalendar(cal)}
>
<Pencil className="size-3" strokeWidth="2" />
</button>
{/if}
{#if isDeletable(cal)}
<button
type="button"
class="shrink-0 p-0.5 mr-2 rounded opacity-0 group-hover:opacity-100 group-focus-within:opacity-100
transition-all duration-150"
title={$i18n.t('Delete calendar')}
on:click|stopPropagation={(e) => handleDeleteClick(e, cal)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
</svg>
</button>
{/if}
</div>
{/each}
</div>
</div>
@@ -5,6 +5,7 @@
import Modal from '$lib/components/common/Modal.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import { createCalendar, updateCalendar, type CalendarModel } from '$lib/apis/calendar';
@@ -17,6 +18,7 @@
let name = '';
let color = '#3b82f6';
let loading = false;
let showDeleteConfirm = false;
const PRESET_COLORS = [
'#3b82f6', // blue
@@ -131,9 +133,19 @@
</div>
<!-- Bottom toolbar -->
<div class="flex items-center justify-end px-4 pb-3.5 pt-2 gap-2">
<div class="flex items-center px-4 pb-3.5 pt-2 gap-2">
{#if calendar && !calendar.is_default && !calendar.is_system}
<button
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2.5 text-xs font-normal text-base-600 transition hover:bg-base-100 hover:text-base-900 disabled:opacity-60 dark:text-base-400 dark:hover:bg-base-850 dark:hover:text-base-0"
type="button"
on:click={() => (showDeleteConfirm = true)}
disabled={loading}
>
{$i18n.t('Delete')}
</button>
{/if}
<button
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2.5 text-xs font-normal text-base-600 transition hover:bg-base-100 hover:text-base-900 disabled:opacity-60 dark:text-base-400 dark:hover:bg-base-850 dark:hover:text-base-0"
class="ml-auto flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2.5 text-xs font-normal text-base-600 transition hover:bg-base-100 hover:text-base-900 disabled:opacity-60 dark:text-base-400 dark:hover:bg-base-850 dark:hover:text-base-0"
type="button"
on:click={() => (show = false)}
>
@@ -153,3 +165,17 @@
</div>
</div>
</Modal>
<ConfirmDialog
bind:show={showDeleteConfirm}
title={$i18n.t('Delete Calendar')}
message={$i18n.t(
'This will permanently delete the calendar "{{name}}" and all its events. This action cannot be undone.',
{ name: calendar?.name ?? '' }
)}
confirmLabel={$i18n.t('Delete')}
onConfirm={() => {
dispatch('delete', calendar?.id);
show = false;
}}
/>