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

250 lines
7.1 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 {
FEEDBIN_DEFAULT_URL,
authenticationUrl,
authorizationHeader,
encodeBasicToken,
normalizeFeedbinUrl,
} from '../../../config/feedbin';
export default class SettingsIntegrationsFeedbinForm extends Component {
@service http;
@service notifications;
@service sites;
@service storage;
@tracked urlDraft = null;
@tracked emailDraft = null;
@tracked password = '';
@tracked error = null;
@tracked submitting = false;
get integration() {
return this.args.props?.integration;
}
get isEdit() {
return this.args.props?.mode === 'edit';
}
get url() {
return this.urlDraft ?? this.integration?.url ?? FEEDBIN_DEFAULT_URL;
}
get defaultUrl() {
return FEEDBIN_DEFAULT_URL;
}
get email() {
return this.emailDraft ?? this.integration?.email ?? '';
}
get title() {
return this.isEdit ? 'Edit Feedbin' : 'Add Feedbin Integration';
}
get submitLabel() {
return this.isEdit ? 'Save' : 'Connect';
}
@action
updateUrl(event) {
this.urlDraft = event.target.value;
this.error = null;
}
@action
updateEmail(event) {
this.emailDraft = event.target.value;
this.error = null;
}
@action
updatePassword(event) {
this.password = event.target.value;
this.error = null;
}
@action
async handleSubmit(event) {
event.preventDefault();
this.error = null;
const instanceUrl = normalizeFeedbinUrl(this.url);
if (!instanceUrl) {
this.error = 'Please enter a valid Feedbin URL';
return;
}
const email = this.email.trim();
if (!email) {
this.error = 'Please enter your Feedbin email';
return;
}
// On edit a blank password keeps the stored token, so users can change
// their email without re-entering the password.
const token = this.password
? encodeBasicToken(email, this.password)
: this.integration?.token;
if (!token) {
this.error = 'Please enter your Feedbin password';
return;
}
this.submitting = true;
try {
await this.http.request(authenticationUrl(instanceUrl), {
headers: {
Authorization: authorizationHeader(token),
Accept: 'application/json',
},
});
} catch (err) {
this.error = this.classifyError(err);
return;
} finally {
this.submitting = false;
}
// Only the credential fields are persisted; the edit row also carries
// display-only fields (avatar, labels) that must not be stored.
await this.storage.set('integrations', 'feedbin', {
type: 'feedbin',
status: 'active',
url: instanceUrl,
email,
token,
createdAt: this.integration?.createdAt ?? Date.now(),
});
await this.sites.reload();
this.notifications.startPolling();
this.args.close?.();
}
classifyError(err) {
if (err?.status === 401 || err?.status === 403) {
return 'Invalid email or password';
}
if (err?.name === 'NetworkError') {
return 'Unable to reach Feedbin. Check your connection.';
}
return 'Unable to verify your Feedbin credentials';
}
<template>
<div class="p-6">
<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">
Connect your Feedbin account to see the unread count on your
dashboard.
</p>
</div>
<form {{on "submit" this.handleSubmit}} class="mt-5">
<div class="space-y-5">
<div>
<label
for="feedbin-url"
class="block text-sm font-medium leading-6 text-gray-900"
>
Server URL
</label>
<div class="mt-2">
<input
type="text"
inputmode="url"
id="feedbin-url"
name="url"
value={{this.url}}
{{on "input" this.updateUrl}}
placeholder={{this.defaultUrl}}
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">
Leave as-is unless you self-host Feedbin.
</p>
</div>
<div>
<label
for="feedbin-email"
class="block text-sm font-medium leading-6 text-gray-900"
>
Email
</label>
<div class="mt-2">
<input
type="email"
id="feedbin-email"
name="email"
autocomplete="username"
value={{this.email}}
{{on "input" this.updateEmail}}
placeholder="you@example.com"
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>
</div>
<div>
<label
for="feedbin-password"
class="block text-sm font-medium leading-6 text-gray-900"
>
Password
</label>
<div class="mt-2">
<input
type="password"
id="feedbin-password"
name="password"
autocomplete="current-password"
value={{this.password}}
{{on "input" this.updatePassword}}
placeholder={{if this.isEdit "Leave blank to keep current" ""}}
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>
</div>
{{#if this.error}}
<p class="text-sm text-red-600">{{this.error}}</p>
{{/if}}
</div>
<div class="mt-5 sm:mt-6 flex gap-3">
<button
type="submit"
disabled={{this.submitting}}
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 disabled:opacity-50"
>
{{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>
}