agent-orchestrator/ui-electrobun/src/mainview/notifications-store.svelte.ts
Hibryda c88577a34a refactor(electrobun): modularize stores + shared UI components
Stores:
- notifications-store.svelte.ts: owns notifications array (was inline in App)
- workspace-store.svelte.ts: extended with addProjectFromWizard, loadGroupsFromDb,
  loadProjectsFromDb, derived getters (totalCost, totalTokens, mountedGroupIds)

Shared UI components (ui/):
- SegmentedControl.svelte: replaces repeated .seg button groups
- SliderInput.svelte: labeled range slider with value display
- StatusDot.svelte: colored dot with pulse support
- IconButton.svelte: icon-only button with tooltip, 3 sizes
- Section.svelte: settings section wrapper with heading

App.svelte: script 390→221 lines (removed all inline CRUD, delegates to stores)
ProjectCard: uses StatusDot shared component
AgentSettings + OrchestrationSettings: use SegmentedControl, SliderInput, Section
2026-03-23 19:42:47 +01:00

49 lines
1.9 KiB
TypeScript

/**
* Notifications store — owns notification list and toast integration.
*
* Extracted from App.svelte inline state (Phase 2).
*/
// ── Types ─────────────────────────────────────────────────────────────────
export interface Notification {
id: number;
message: string;
type: 'success' | 'warning' | 'info' | 'error';
time: string;
}
// ── State ─────────────────────────────────────────────────────────────────
let notifications = $state<Notification[]>([
{ id: 1, message: 'Agent completed: wake scheduler implemented', type: 'success', time: '2m ago' },
{ id: 2, message: 'Context pressure: 78% on agent-orchestrator', type: 'warning', time: '5m ago' },
{ id: 3, message: 'PTY daemon connected', type: 'info', time: '12m ago' },
]);
let nextId = $state(100);
// ── Public API ────────────────────────────────────────────────────────────
export function getNotifications(): Notification[] {
return notifications;
}
export function getNotifCount(): number {
return notifications.length;
}
export function addNotification(message: string, type: Notification['type'] = 'info'): void {
const now = new Date();
const time = `${now.getHours()}:${String(now.getMinutes()).padStart(2, '0')}`;
const id = nextId++;
notifications = [{ id, message, type, time }, ...notifications].slice(0, 100);
}
export function removeNotification(id: number): void {
notifications = notifications.filter(n => n.id !== id);
}
export function clearAll(): void {
notifications = [];
}