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

61 lines
1.5 KiB
JavaScript

import { CALENDAR_ACTOR } from './calendar-actor';
export const ICS_TYPE = 'calendar-ics';
// A published feed is either an http(s) URL or a webcal:// link. Sockethub
// fetches webcal links over HTTPS, so both are accepted as-is.
export function normalizeFeedUrl(input) {
const value = (input ?? '').trim();
if (!value || /\s/.test(value) || !/^(https?|webcal):\/\//i.test(value)) {
return null;
}
try {
return new URL(value).href;
} catch {
return null;
}
}
// Short, stable hash so a feed's storage key stays tidy.
function hash(value) {
let result = 5381;
for (let index = 0; index < value.length; index += 1) {
result = ((result << 5) + result + value.charCodeAt(index)) >>> 0;
}
return result.toString(36);
}
export function icsInstanceKey(url) {
const normalized = normalizeFeedUrl(url);
if (!normalized) {
return null;
}
return `${ICS_TYPE}-${new URL(normalized).host}-${hash(normalized)}`;
}
export function readMessage(context, url, { startTime, endTime }) {
return {
'@context': context,
type: 'read',
actor: CALENDAR_ACTOR,
target: { id: url, type: 'feed' },
object: { type: 'event', startTime, endTime },
};
}
// The feed's display name, from X-WR-CALNAME (`summary`) with a host fallback.
export function feedName(response, url) {
if (typeof response?.summary === 'string' && response.summary.trim()) {
return response.summary.trim();
}
try {
return new URL(url).hostname;
} catch {
return 'Calendar';
}
}