Spaces:
Build error
Build error
File size: 6,258 Bytes
87a665c | 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | <script lang="ts">
import { getContext } from 'svelte';
import type { CalendarModel } from '$lib/apis/calendar';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
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 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) {
onDeleteCalendar(deleteTargetCalendar.id);
}
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();
}
function isSelected(d: Date): boolean {
return 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 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-[11px] font-medium">{miniMonthNames[miniMonth]} {miniYear}</div>
<div class="flex items-center gap-0.5">
<button
class="p-0.5 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition"
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="p-0.5 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition"
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-[9px] text-gray-400 dark:text-gray-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-[10px]">
{#each miniDays as day}
<button
class="w-6 h-6 flex items-center justify-center rounded-full transition
{day.getMonth() !== miniMonth ? 'text-gray-300 dark:text-gray-600' : ''}
{isToday(day) ? 'bg-blue-500 text-white' : ''}
{day.toDateString() === currentDate.toDateString() && !isToday(day)
? 'bg-gray-200 dark:bg-gray-700'
: ''}
{!isToday(day) && day.toDateString() !== currentDate.toDateString()
? 'hover:bg-gray-100 dark:hover:bg-gray-800'
: ''}"
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-[11px] text-gray-400 dark:text-gray-500 uppercase tracking-wider">
{$i18n.t('Calendars')}
</div>
</div>
{#each calendars as cal (cal.id)}
<div class="group flex items-center w-full">
<button
class="flex items-center gap-2 px-2 py-1 rounded-lg text-xs transition
hover:bg-gray-50 dark:hover:bg-gray-800/50 flex-1 text-left min-w-0"
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-gray-400 dark:text-gray-500'}"
>
{cal.name}
</span>
{#if isDeletable(cal)}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span
class="shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100
transition-all duration-150"
role="button"
tabindex="-1"
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>
</span>
{/if}
</button>
</div>
{/each}
</div>
</div>
|