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

180 lines
5.4 KiB
Plaintext

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import {
DEFAULT_SOCKETHUB_URL,
normalizeSockethubUrl,
} from '../../../../config/sockethub';
import {
SOCKETHUB_STATUS_CONNECTING,
SOCKETHUB_STATUS_ERROR,
SOCKETHUB_STATUS_READY,
} from '../../../../services/sockethub';
// Sockethub (the protocol gateway) settings. Dashtab talks to a single
// Sockethub server for every integration that needs one; this section explains
// what that is and lets the user point Dashtab at another instance.
export default class SettingsProtocolGateway extends Component {
@service sockethub;
@tracked urlDraft = null;
@tracked error = null;
@tracked saved = false;
constructor(owner, args) {
super(owner, args);
// `sockethub.url` is only populated when a connection opens, so load the
// stored value eagerly. Otherwise the field would show the default even
// when a custom URL is saved, and saving would overwrite it.
this.sockethub.loadUrl();
}
get url() {
return this.urlDraft ?? this.sockethub.url ?? DEFAULT_SOCKETHUB_URL;
}
get statusLabel() {
switch (this.sockethub.status) {
case SOCKETHUB_STATUS_READY:
return 'Connected';
case SOCKETHUB_STATUS_CONNECTING:
return 'Connecting…';
case SOCKETHUB_STATUS_ERROR:
return this.sockethub.error
? `Last error: ${this.sockethub.error}`
: 'Connection failed';
default:
return 'Not connected';
}
}
get statusDotClass() {
switch (this.sockethub.status) {
case SOCKETHUB_STATUS_READY:
return 'bg-green-500';
case SOCKETHUB_STATUS_ERROR:
return 'bg-red-500';
default:
return 'bg-gray-400';
}
}
@action
updateUrl(event) {
this.urlDraft = event.target.value;
this.error = null;
this.saved = false;
}
@action
async save(event) {
event.preventDefault();
this.error = null;
this.saved = false;
const url = normalizeSockethubUrl(this.url);
if (!url) {
this.error = 'Please enter a valid Sockethub server URL';
return;
}
try {
await this.sockethub.setUrl(url);
this.urlDraft = url;
this.saved = true;
} catch (err) {
this.error = err?.message ?? 'Unable to reach that Sockethub server';
}
}
<template>
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
<div class="max-w-prose space-y-3 text-sm text-gray-500">
<p>
Sockethub is a protocol gateway: it lets Dashtab reach services a
browser cannot talk to directly — currently CalDAV calendars — by
exchanging data via this specialized proxy server.
</p>
<p>
Dashtab talks to a single Sockethub server. Most people can keep the
default; credentials are encrypted on the server and never logged or
saved.
</p>
<p>
Self-hosters can point it at their own instance for maximum privacy
and security.
</p>
<p>
<a
href="https://sockethub.org"
target="_blank"
rel="noopener noreferrer"
class="text-indigo-600 hover:text-indigo-500"
>Learn more at sockethub.org</a>.
</p>
</div>
<form {{on "submit" this.save}} class="mt-6 max-w-lg">
<label
for="sockethub-url"
class="block text-sm font-medium leading-6 text-gray-900"
>
Sockethub server URL
</label>
<div class="mt-2">
<input
type="text"
inputmode="url"
id="sockethub-url"
name="sockethub-url"
value={{this.url}}
{{on "input" this.updateUrl}}
placeholder={{DEFAULT_SOCKETHUB_URL}}
class="block w-full rounded-md border-0 px-3 py-2 text-sm text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600"
/>
</div>
<p class="mt-2 text-sm text-gray-500">
The Sockethub instance Dashtab talks to.
</p>
{{#if this.error}}
<p data-test-error class="mt-3 text-sm text-red-600" role="alert">
{{this.error}}
</p>
{{/if}}
<div class="mt-4 flex items-center gap-3">
<button
type="submit"
class="inline-flex 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-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
Save
</button>
{{#if this.saved}}
<span data-test-saved class="text-sm text-green-600" role="status">
Saved
</span>
{{/if}}
</div>
</form>
<div class="mt-8 border-t border-gray-200 pt-4 text-sm text-gray-500">
<p class="flex items-center gap-2">
<span
class="size-2 shrink-0 rounded-full {{this.statusDotClass}}"
aria-hidden="true"
></span>
<span data-test-status role="status">{{this.statusLabel}}</span>
</p>
<p class="mt-1 text-xs text-gray-400">
Sockethub connects on demand only when it's needed.
</p>
</div>
</div>
</template>
}