Federal holidays in the app, national days from Checkiday in the app and/or exports

This commit is contained in:
iamdoubz committed 2026-11-09 21:46:05 -06:00
1 parent 935b990855
commit d3cb3f8d47
19 files changed
+375 -20

No files matched your search

+1
View File
@@ -262,6 +262,7 @@ textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
display: flex; gap: var(--s2); align-items: flex-start;
padding: var(--s3) var(--s4); border-radius: var(--r-md); font-size: var(--fs-sm);
}
.alert > svg { flex: none; } /* long text would squeeze the icon to a dot */
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
+6
View File
@@ -13,9 +13,15 @@ export interface Source {
export interface Household {
timezone: string; show_scan_stats: boolean; public_url: string;
about: { version: string; commit: string; repo_url: string };
holidays: { federal_holidays: 'off' | 'app'; national_days: 'off' | 'app' | 'export' | 'both'; checkiday: boolean };
children: Child[]; calendars: Calendar[]; sources: Source[];
}
/** Shown in the app only, never edited: a federal holiday, or one day's national days (from Checkiday). */
export type Observance =
| { kind: 'federal'; date: string; name: string; observed: string }
| { kind: 'national'; date: string; names: { id: string; name: string; url: string }[] };
export interface CalEvent {
id: number; uid: string; scan_id: number | null; source_id: number | null;
date: string; end_date: string | null; all_day: boolean; start_time: string | null; end_time: string | null;
+59 -4
View File
@@ -5,13 +5,16 @@
import ChevronRight from '@lucide/svelte/icons/chevron-right';
import CircleAlert from '@lucide/svelte/icons/circle-alert';
import Copy from '@lucide/svelte/icons/copy';
import ChevronDown from '@lucide/svelte/icons/chevron-down';
import Download from '@lucide/svelte/icons/download';
import FileDown from '@lucide/svelte/icons/file-down';
import Flag from '@lucide/svelte/icons/flag';
import LayoutGrid from '@lucide/svelte/icons/layout-grid';
import List from '@lucide/svelte/icons/list';
import MapPin from '@lucide/svelte/icons/map-pin';
import PartyPopper from '@lucide/svelte/icons/party-popper';
import Rss from '@lucide/svelte/icons/rss';
import { api, KINDS, type CalEvent, type EventValues } from '../lib/api';
import { api, KINDS, type CalEvent, type EventValues, type Observance } from '../lib/api';
import { app, setHousehold, toast } from '../lib/state.svelte';
import { iso, monthEnd, monthLabel, parse, shiftMonth, thisMonth, whenLabel } from '../lib/dates';
import { KIND_ICONS } from '../lib/icons';
@@ -26,6 +29,7 @@
let month = $state(thisMonth());
let view = $state<'list' | 'grid'>('list');
let events = $state<CalEvent[] | null>(null);
let observances = $state<Observance[]>([]); // holidays: shown here, never edited
let editing = $state<number | 'new' | null>(null);
let newDate = $state('');
let editDay = $state(''); // a multi-day event is listed on each day; its editor opens under the one tapped
@@ -40,6 +44,7 @@
const colorFor = (e: CalEvent) => children.get(e.child_ids[0])?.color ?? calendar?.color ?? 'var(--primary)';
const byDay = $derived.by(() => {
const days = new Map<string, CalEvent[]>();
for (const o of observances) if (!days.has(o.date)) days.set(o.date, []); // a holiday's day is listed even with no events
const last = monthEnd(month);
for (const e of events ?? []) {
// A multi-day event shows on each of its days in this month.
@@ -51,6 +56,8 @@
}
return [...days.entries()].sort();
});
const obsOn = (day: string) => observances.filter((o) => o.date === day);
const shortDay = (d: string) => parse(d).toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' });
const today = iso(new Date());
// The subscription feed: the one public URL, so it uses PUBLIC_URL. webcal:// opens the phone's subscribe screen.
const feedUrl = $derived(calendar ? `${app.household!.public_url}/feed/${calendar.feed_token}.ics` : '');
@@ -80,7 +87,11 @@
error = '';
events = null;
try {
events = await api<CalEvent[]>(`/events?calendar_id=${calendarId}&start=${month}-01&end=${monthEnd(month)}`);
const range = `start=${month}-01&end=${monthEnd(month)}`;
[events, observances] = await Promise.all([
api<CalEvent[]>(`/events?calendar_id=${calendarId}&${range}`),
api<Observance[]>(`/observances?${range}`),
]);
} catch (e: any) {
error = e.message;
}
@@ -189,8 +200,8 @@
{#each [1, 2, 3] as _}<div class="skeleton" style="height:64px"></div>{/each}
</div>
{:else if view === 'grid'}
<MonthGrid {month} {events} {colorFor} onday={addOn} showTitle={false} />
{:else if !events.length}
<MonthGrid {month} {events} {observances} {colorFor} onday={addOn} showTitle={false} />
{:else if !byDay.length}
<EmptyState icon={CalendarDays} title="Nothing this month">
<p>Publish a scan, or add an event by hand.</p>
</EmptyState>
@@ -207,6 +218,34 @@
</div>
{#if isToday}<span class="visually-hidden">Today</span>{/if}
<ul class="card-list grow">
{#each obsOn(day) as o (o.kind)}
{#if o.kind === 'federal'}
<li class="obs federal">
<span class="kind"><Flag size={18} aria-hidden="true" /></span>
<span class="grow">
<span class="title">{o.name}</span>
<span class="meta">Federal holiday{#if o.observed !== o.date} · observed {shortDay(o.observed)}{/if}</span>
</span>
</li>
{:else}
<li class="obs national">
<details>
<summary>
<span class="kind"><PartyPopper size={18} aria-hidden="true" /></span>
<span class="grow">
<span class="title">{o.names[0].name}{#if o.names.length > 1}{' '}<span class="more">+ {o.names.length - 1} more</span>{/if}</span>
<span class="meta">National days</span>
</span>
<ChevronDown size={18} class="chev" aria-hidden="true" />
</summary>
<ul class="names">
{#each o.names as n (n.id)}<li><a href={n.url} target="_blank" rel="noopener">{n.name}</a></li>{/each}
</ul>
<p class="hint credit">From <a href="https://www.checkiday.com" target="_blank" rel="noopener">Checkiday</a></p>
</details>
</li>
{/if}
{/each}
{#each list as e (e.id)}
{@const KindIcon = KIND_ICONS[e.kind]}
<li class="event" style:--child={colorFor(e)}>
@@ -260,4 +299,20 @@
.kind { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); }
.title { display: block; font-weight: 650; color: var(--text); }
.meta { display: block; font-size: var(--fs-sm); color: var(--text-2); }
/* Holidays: flatter than events (no child color, no shadow) since they can't be edited. */
.obs { border: 1px dashed var(--border-strong); border-radius: var(--r-lg); padding: var(--s1) var(--s2); background: var(--surface-2); }
.obs > .kind, .obs summary .kind { background: var(--surface); }
.federal { display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: var(--s1) var(--s3); }
.federal .kind { color: var(--info); }
.national .kind { color: var(--warn); }
.national summary { display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: var(--s1); cursor: pointer; list-style: none; }
.national summary::-webkit-details-marker { display: none; }
.national summary:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: var(--r-md); }
.national :global(.chev) { flex: none; color: var(--text-2); transition: transform var(--dur) var(--ease); }
.national details[open] :global(.chev) { transform: rotate(180deg); }
.more { font-weight: 500; color: var(--text-2); }
.names { list-style: none; margin: 0; padding: 0 var(--s2) var(--s1) calc(36px + var(--s4)); display: flex; flex-direction: column; }
.names a { display: block; padding: var(--s2) 0; min-height: 44px; }
.credit { padding: 0 var(--s2) var(--s2) calc(36px + var(--s4)); margin: 0; }
</style>
+24 -3
View File
@@ -1,16 +1,20 @@
<script lang="ts">
import type { CalEvent } from '../lib/api';
import Flag from '@lucide/svelte/icons/flag';
import PartyPopper from '@lucide/svelte/icons/party-popper';
import type { CalEvent, Observance } from '../lib/api';
import { iso, monthLabel, monthWeeks, parse } from '../lib/dates';
let {
month,
events,
observances = [],
colorFor = () => 'var(--primary)',
onday = null,
showTitle = true,
}: {
month: string;
events: CalEvent[];
observances?: Observance[];
colorFor?: (e: CalEvent) => string;
onday?: ((date: string) => void) | null;
showTitle?: boolean;
@@ -31,6 +35,10 @@
}
return m;
});
const holiday = (day: string) => observances.find((o) => o.date === day && o.kind === 'federal') as
Extract<Observance, { kind: 'federal' }> | undefined;
const funDays = (day: string) => observances.find((o) => o.date === day && o.kind === 'national') as
Extract<Observance, { kind: 'national' }> | undefined;
// Weekday names in the device's language, Sunday first (2026-01-04 was a Sunday).
const names = Array.from({ length: 7 }, (_, i) => new Date(2026, 0, 4 + i).toLocaleDateString(undefined, { weekday: 'short' }));
const today = iso(new Date());
@@ -45,8 +53,15 @@
{#each week as day}
{@const list = byDay.get(day) ?? []}
{@const outside = day.slice(0, 7) !== month}
{@const fed = holiday(day)}
{@const fun = funDays(day)}
{#snippet cell()}
<span class="num tabular">{parse(day).getDate()}</span>
<span class="top">
<span class="num tabular">{parse(day).getDate()}</span>
{#if fed}<span class="mark federal" title={fed.name}><Flag size={12} aria-hidden="true" /></span>{/if}
{#if fun}<span class="mark national" title={`${fun.names.length} national days`}><PartyPopper size={12} aria-hidden="true" /></span>{/if}
</span>
{#if fed}<span class="hol" title={fed.name}>{fed.name}</span>{/if}
{#each list.slice(0, 3) as e (e.id)}
<span class="chip" style:--c={colorFor(e)} title={e.title}>{e.title}</span>
{/each}
@@ -54,7 +69,7 @@
{/snippet}
{#if onday}
<button type="button" class="day" class:outside class:today={day === today} onclick={() => onday(day)}
aria-label={`${longDay(day)}: ${list.length} ${list.length === 1 ? 'event' : 'events'}. Add an event`}>
aria-label={`${longDay(day)}${fed ? `, ${fed.name}` : ''}: ${list.length} ${list.length === 1 ? 'event' : 'events'}. Add an event`}>
{@render cell()}
</button>
{:else}
@@ -85,9 +100,15 @@
background: color-mix(in srgb, var(--c) 20%, var(--surface)); border-left: 3px solid var(--c); color: var(--text);
}
.more { color: var(--text-2); font-weight: 600; }
.top { display: flex; align-items: center; gap: 2px; }
.mark { display: grid; place-items: center; }
.mark.federal { color: var(--info); }
.mark.national { color: var(--warn); }
.hol { display: block; padding: 1px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: italic; color: var(--info); }
@media (min-width: 768px) { .day { min-height: 96px; } }
/* Phones: a cell fits 3-4 letters of a title, so show each event as a colored bar; List view has the titles. */
@media (max-width: 599px) {
.chip { height: 6px; padding: 0; border: 0; border-radius: 3px; font-size: 0; background: var(--c); }
.hol { display: none; } /* the flag by the day number says it; List view has the name */
}
</style>
+29
View File
@@ -1,7 +1,9 @@
<script lang="ts">
import CalendarDays from '@lucide/svelte/icons/calendar-days';
import Check from '@lucide/svelte/icons/check';
import CircleAlert from '@lucide/svelte/icons/circle-alert';
import ChevronRight from '@lucide/svelte/icons/chevron-right';
import Flag from '@lucide/svelte/icons/flag';
import Globe from '@lucide/svelte/icons/globe';
import Info from '@lucide/svelte/icons/info';
import Monitor from '@lucide/svelte/icons/monitor';
@@ -305,6 +307,32 @@
{#if isEditing('source', null)}{@render sourceForm()}{:else}<button class="add" onclick={() => edit('source', null)}><Plus size={18} aria-hidden="true" />Add a source</button>{/if}
</section>
<section class="card section-card">
{@render heading(Flag, 'Holidays', 'Shown on the Calendar tab without being added as events.')}
<div class="setting">
<span class="strong">Federal holidays</span>
<Segmented label="Federal holidays" options={[{ value: 'off', label: 'Off' }, { value: 'app', label: 'Show in the app' }]}
bind:value={() => h.holidays.federal_holidays, (v) => send('/user', 'PUT', { federal_holidays: v })} />
<p class="hint">Veterans Day, Thanksgiving and the other 9. Never in downloads or subscriptions, since phones already show them.</p>
</div>
<div class="setting">
<span class="strong">National days</span>
<Segmented label="National days" options={[{ value: 'off', label: 'Off' }, { value: 'app', label: 'App' }, { value: 'export', label: 'Export' }, { value: 'both', label: 'Both' }]}
bind:value={() => h.holidays.national_days, (v) => send('/user', 'PUT', { national_days: v })} />
<p class="hint">
Days like National Chicken Sandwich Day, from <a href="https://www.checkiday.com" target="_blank" rel="noopener">Checkiday</a>.
App shows them on the Calendar tab; Export adds one all-day event a day, with no alert, to downloads and subscriptions.
Each day's list arrives that morning; days ahead aren't known yet.
</p>
{#if h.holidays.national_days !== 'off' && !h.holidays.checkiday}
<div class="alert warn" role="status">
<CircleAlert size={18} aria-hidden="true" />
<span>Nothing will arrive until the server has a Checkiday key: set <code>CHECKIDAY_API_KEY</code> (free at <a href="https://marketplace.apilayer.com/checkiday-api" target="_blank" rel="noopener">APILayer</a>) and restart it.</span>
</div>
{/if}
</div>
</section>
<section class="card section-card">
{@render heading(Info, 'About', '')}
<dl class="about">
@@ -324,6 +352,7 @@
<style>
.section-card { display: flex; flex-direction: column; gap: var(--s4); }
.setting { display: flex; flex-direction: column; gap: var(--s2); align-items: flex-start; }
.about { display: flex; flex-direction: column; gap: var(--s2); margin: 0; }
.about div { display: flex; justify-content: space-between; gap: var(--s3); min-height: 32px; align-items: center; }
.about dt { color: var(--text-2); }