feat(notifications): P4 WebUI — channel manager, per-account opt-in, deliveries widget

- API client: notifications surface (getConfig/saveConfig/recent/test) + types.
- Settings → 通知 tab: global channel CRUD (id/name/url/body-template/enabled) +
  global debounce window, per-channel test-send, dirty-tracked save; invalid
  channels (bad slug / non-http URL) are dropped server-side and surfaced.
- Per-account 通用设置: opt-in toggles bound to notifications.channelIds, riding
  the ConfigPage's existing debounced autosave; stale opt-ins preserved.
- Overview: opt-in 最近投递 widget (polls /api/notifications/recent, read-only).
  Hidden-by-default set is now DERIVED from the catalogue (defaultVisible) and
  shared by desktop + mobile reconcile — replaces the hardcoded STATIC_WIDGET_IDS
  so a new opt-in widget can't reappear unbidden on existing mobile dashboards.

Typecheck + build green. Adversarial review: 1 should-fix (mobile hidden-set) +
2 nits found, fixed/triaged, and re-verified clean.
This commit is contained in:
DrSmoothl committed 2026-06-16 19:53:31 +08:00
1 parent c0af18e1c2
commit 0b7fb0c69d
12 files changed
+509 -7

No files matched your search

@@ -22,7 +22,7 @@ import { useTheme } from '@/contexts/ThemeContext';
import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
import { useMediaQuery } from '@/hooks/use-media-query';
import {
CONFIGURABLE_WIDGETS, GRID_COLS, GRID_WIDGETS, MOBILE_WIDGET_IDS, STATIC_WIDGET_IDS, mobileHeightOf,
CONFIGURABLE_WIDGETS, GRID_COLS, GRID_WIDGETS, HIDDEN_BY_DEFAULT_IDS, MOBILE_WIDGET_IDS, mobileHeightOf,
parseAccountConfig, parseAlertsConfig, parseConnectionsConfig, parseHostConfig,
parseLinkConfig, parseNoteConfig, parseSessionsConfig, widgetLabel,
type AccountConfig, type AlertsConfig, type ConnectionsConfig, type HostConfig,
@@ -34,6 +34,7 @@ import {
AccountConfigForm, AlertsConfigForm, ConnectionsConfigForm, HostConfigForm,
LinkConfigForm, LINK_ICON_COMPONENTS, NoteConfigForm, SessionsConfigForm,
} from '@/components/pages/widget-config-forms';
import { DeliveriesWidget } from '@/components/overview/deliveries-widget';
function qqAvatarUrl(uin: string) {
return `/avatar/${encodeURIComponent(uin)}`;
@@ -49,6 +50,7 @@ function renderWidget(block: UiLayoutItem): ReactNode {
case 'note': return <NoteWidget config={parseNoteConfig(block.config)} />;
case 'link': return <LinkWidget config={parseLinkConfig(block.config)} />;
case 'account': return <AccountWidget config={parseAccountConfig(block.config)} />;
case 'deliveries': return <DeliveriesWidget />;
default: return null;
}
}
@@ -78,7 +80,7 @@ export function OverviewPage() {
// Reconcile the mobile order against the live widget catalogue (drop unknown,
// append new as visible) — so a widget added later just appears on phones too.
const mobileItems = useMemo(
() => reconcileLayoutItems(overviewMobile, MOBILE_WIDGET_IDS, [], STATIC_WIDGET_IDS),
() => reconcileLayoutItems(overviewMobile, MOBILE_WIDGET_IDS, [], HIDDEN_BY_DEFAULT_IDS),
[overviewMobile],
);
@@ -1,7 +1,7 @@
import { createContext, useContext, useId, useRef, useState, type ReactNode } from 'react';
import { motion } from 'motion/react';
import {
Accessibility, AlertTriangle, Bug, Check, Clock, Code2, Download, ExternalLink, Github, Image as ImageIcon,
Accessibility, AlertTriangle, Bell, Bug, Check, Clock, Code2, Download, ExternalLink, Github, Image as ImageIcon,
Info, KeyRound, Loader2, Monitor, Moon, Palette, PanelTop, Plus, RefreshCw, RotateCcw, ShieldCheck,
Sparkles, Star, Sun, Tag, Upload, Trash2,
} from 'lucide-react';
@@ -40,12 +40,14 @@ import { useApi } from '@/lib/api';
import { useAppState } from '@/contexts/AppStateContext';
import { cn } from '@/lib/utils';
import { settingsRoute, type SettingsTab } from '@/router';
import { NotificationsPanel } from '@/components/settings/notifications-panel';
const TABS: { key: SettingsTab; label: string; icon: typeof Sun }[] = [
{ key: 'appearance', label: '外观', icon: Palette },
{ key: 'data', label: '数据与格式', icon: RefreshCw },
{ key: 'advanced', label: '高级', icon: Code2 },
{ key: 'account', label: '账号安全', icon: ShieldCheck },
{ key: 'notifications', label: '通知', icon: Bell },
{ key: 'about', label: '关于', icon: Info },
];
@@ -76,6 +78,7 @@ export function SettingsPage() {
{tab === 'data' && <DataPanel />}
{tab === 'advanced' && <AdvancedPanel />}
{tab === 'account' && <AccountPanel />}
{tab === 'notifications' && <NotificationsPanel />}
{tab === 'about' && <AboutPanel />}
</motion.div>
</div>