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

160 lines
4.2 KiB
Plaintext

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { on } from '@ember/modifier';
import { modifier } from 'ember-modifier';
import SettingsSelect from './select.gjs';
import {
BITCOIN_DEFAULT_INTERVAL,
BITCOIN_DEFAULT_PROVIDER,
BITCOIN_INTERVAL_OPTIONS,
BITCOIN_PROVIDERS,
} from '../../../services/bitcoin';
export default class SettingsIntegrationsBitcoinForm extends Component {
@service bitcoin;
// User edits are kept as drafts so the displayed values can fall back to the
// persisted integration or the live service state. This keeps the form safe
// to mount anywhere, even before the bitcoin service has finished loading.
@tracked intervalDraft = null;
@tracked providerDraft = null;
get integration() {
return this.args.props?.integration;
}
get interval() {
return (
this.intervalDraft ??
this.integration?.interval ??
this.bitcoin.interval ??
BITCOIN_DEFAULT_INTERVAL
);
}
get provider() {
return (
this.providerDraft ??
this.integration?.provider ??
this.bitcoin.provider ??
BITCOIN_DEFAULT_PROVIDER
);
}
resetOnClose = modifier((element) => {
const dialog = element.closest('dialog');
if (!dialog) {
return;
}
const handleClose = () => {
this.intervalDraft = null;
this.providerDraft = null;
};
dialog.addEventListener('close', handleClose);
return () => dialog.removeEventListener('close', handleClose);
});
get isEdit() {
return this.args.props?.mode === 'edit';
}
get title() {
return this.isEdit
? 'Edit Bitcoin Price Ticker'
: 'Add Bitcoin Price Ticker';
}
get submitLabel() {
return this.isEdit ? 'Save' : 'Enable';
}
get intervalOptions() {
return BITCOIN_INTERVAL_OPTIONS;
}
get providerOptions() {
return BITCOIN_PROVIDERS.map(({ id, label }) => ({ value: id, label }));
}
@action
updateInterval(value) {
this.intervalDraft = Number(value);
}
@action
updateProvider(value) {
this.providerDraft = value;
}
@action
async handleSubmit(event) {
event.preventDefault();
if (this.isEdit) {
await this.bitcoin.update(this.interval, this.provider);
} else {
await this.bitcoin.enable(this.interval, this.provider);
}
this.args.close?.();
}
<template>
<div class="p-6" {{this.resetOnClose}}>
<h3
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">
Show the current Bitcoin price at the top of your dashboard.
</p>
</div>
<form {{on "submit" this.handleSubmit}} class="mt-5">
<div class="space-y-5">
<SettingsSelect
@id="bitcoin-provider"
@name="provider"
@label="Price source"
@options={{this.providerOptions}}
@value={{this.provider}}
@onChange={{this.updateProvider}}
/>
<SettingsSelect
@id="bitcoin-interval"
@name="interval"
@label="Update interval"
@options={{this.intervalOptions}}
@value={{this.interval}}
@onChange={{this.updateInterval}}
/>
</div>
<div class="mt-5 sm:mt-6 flex gap-3">
<button
type="submit"
class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
{{this.submitLabel}}
</button>
<button
type="button"
{{on "click" @close}}
class="inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Cancel
</button>
</div>
</form>
</div>
</template>
}