Files
raucao 11f8d3f049 WIP: Add calendar settings and a nested modal stack
Add a 'days with events' preference (default 3, range 1-7) that drives the upcoming events widget, and extend the fetch window to 8 days so the largest window can populate.

Add a Calendar settings pane (moved under Integrations) that lists the connected CalDAV/ICS sources in a two-column grid with add/edit/remove, and remove calendars from Manage Integrations.

Turn the modal service into a stack so add/edit forms open on top of the settings dialog, with one dialog per level, per-entry title ids, and a softened stacked backdrop.

Move CALENDAR_ACTOR into its own config module to break the calendar/caldav/ics import cycle.
2026-11-06 15:48:08 +04:00

125 lines
3.6 KiB
Plaintext

import Component from '@glimmer/component';
import { action } from '@ember/object';
import { modifier } from 'ember-modifier';
const WIDTHS = {
sm: 'sm:max-w-sm',
md: 'sm:max-w-md',
lg: 'sm:max-w-lg',
xl: 'sm:max-w-xl',
'2xl': 'sm:max-w-2xl',
'3xl': 'sm:max-w-3xl',
settings: 'sm:max-w-4xl',
};
const BACKDROP_BASE =
'fixed inset-0 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in';
// Each stacked dialog needs its own title id. Descriptors are plain objects and
// are kept identity-stable by the modal service, so key the ids off the object.
const TITLE_IDS = new WeakMap();
let nextTitleId = 0;
function titleIdFor(descriptor) {
if (!descriptor) {
return 'modal-title';
}
if (!TITLE_IDS.has(descriptor)) {
nextTitleId += 1;
TITLE_IDS.set(descriptor, `modal-title-${nextTitleId}`);
}
return TITLE_IDS.get(descriptor);
}
// One entry in the modal stack. Renders a native <dialog> so each level gets
// its own focus trap and Esc handling; stacked dialogs sit above the ones
// below in the top layer.
export default class ModalEntryComponent extends Component {
dialogElement = null;
get currentComponent() {
return this.args.descriptor?.component;
}
get maxWidthClass() {
const size = this.args.descriptor?.size ?? 'md';
return WIDTHS[size] || WIDTHS.md;
}
// A unique title id per entry so stacked dialogs do not share `#modal-title`.
get titleId() {
return titleIdFor(this.args.descriptor);
}
// The base entry keeps the full scrim; stacked entries use a lighter one so
// the two backdrops do not read as near-black.
get backdropClass() {
return this.args.depth === 0
? `${BACKDROP_BASE} bg-neutral-950/75`
: `${BACKDROP_BASE} bg-neutral-950/50`;
}
trackDialog = modifier((element) => {
this.dialogElement = element;
queueMicrotask(() => {
if (element.isConnected && !element.open) {
element.showModal();
}
});
const handleClose = () => {
this.dialogElement = null;
this.args.onFinished?.();
};
element.addEventListener('close', handleClose);
return () => {
element.removeEventListener('close', handleClose);
this.dialogElement = null;
};
});
@action
close() {
this.dialogElement?.close();
}
@action
replace(descriptor) {
this.args.onReplace?.(descriptor);
}
<template>
<el-dialog>
<dialog
aria-labelledby={{this.titleId}}
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent"
{{this.trackDialog}}
>
<el-dialog-backdrop class={{this.backdropClass}}></el-dialog-backdrop>
<div
tabindex="0"
class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0"
>
<el-dialog-panel
class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full
{{this.maxWidthClass}}
data-closed:sm:translate-y-0 data-closed:sm:scale-95"
>
<this.currentComponent
@props={{@descriptor.props}}
@titleId={{this.titleId}}
@close={{this.close}}
@replace={{this.replace}}
/>
</el-dialog-panel>
</div>
</dialog>
</el-dialog>
</template>
}