hoover: move ToastContainer to separate module, add reactive re-render, bump module cache v8

This commit is contained in:
2026-06-30 04:01:41 +00:00
parent 9088f34345
commit 575cf06a4b
18 changed files with 51 additions and 68 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
import { h, render, Link, hComp, ToastContainer, connect, apiFetch, modelRegister, modelFetch, reactive } from '/static/hoover/index.js?v=8'; import { h, render, Link, hComp, ToastContainer, connect, apiFetch, modelRegister, modelFetch, reactive } from '/static/hoover/index.js?v=9';
import DashboardPage from '/static/pages/dashboard.js?v=8'; import DashboardPage from '/static/pages/dashboard.js?v=8';
import InterfacesPage from '/static/pages/interfaces.js?v=8'; import InterfacesPage from '/static/pages/interfaces.js?v=8';
+4 -23
View File
@@ -3,11 +3,10 @@
* *
* JSON-friendly fetch wrapper with automatic header management. * JSON-friendly fetch wrapper with automatic header management.
* Toast notification system with auto-dismiss. * Toast notification system with auto-dismiss.
* ToastContainer component for rendering queued toasts.
*/ */
import { h } from './vdom.js?v=7'; import { modelFetch } from './model.js?v=8';
import { modelFetch } from './model.js?v=7'; import { requestUpdate } from './reactivity.js?v=8';
/** /**
* JSON-friendly fetch wrapper. * JSON-friendly fetch wrapper.
@@ -65,6 +64,7 @@ const _toastIds = { next: 1 };
export function toast(message, type = 'info', duration = 4000) { export function toast(message, type = 'info', duration = 4000) {
const id = _toastIds.next++; const id = _toastIds.next++;
_toasts.push({ id, message, type, createdAt: Date.now(), duration }); _toasts.push({ id, message, type, createdAt: Date.now(), duration });
requestUpdate();
if (duration > 0) setTimeout(() => dismissToast(id), duration); if (duration > 0) setTimeout(() => dismissToast(id), duration);
return id; return id;
@@ -76,26 +76,7 @@ export function toast(message, type = 'info', duration = 4000) {
export function dismissToast(id) { export function dismissToast(id) {
const idx = _toasts.findIndex(t => t.id === id); const idx = _toasts.findIndex(t => t.id === id);
if (idx !== -1) _toasts.splice(idx, 1); if (idx !== -1) _toasts.splice(idx, 1);
} requestUpdate();
/**
* Render the queued toast notifications.
*
* @returns {VNode} Toast container (empty text node when no toasts)
*/
export function ToastContainer() {
if (!_toasts.length) return h('#text', '');
const clsMap = { info: 'toast-info', success: 'toast-success', error: 'toast-error', warning: 'toast-warning' };
return h('div', { class: 'toast-container' },
..._toasts.map(t =>
h('div', { class: `toast ${clsMap[t.type] || clsMap.info}`, 'on:click': () => dismissToast(t.id) },
h('span', null, t.message),
h('button', { class: 'toast-close', 'on:click': (e) => { e.stopPropagation(); dismissToast(t.id); } }, '\u00d7'),
),
),
);
} }
/** /**
+4 -4
View File
@@ -4,10 +4,10 @@
* Data display components: Badge, StatusDot, Empty, Card. * Data display components: Badge, StatusDot, Empty, Card.
*/ */
import { h } from '../vdom.js?v=7'; import { h } from '../vdom.js?v=8';
import { esc } from '../helpers.js?v=7'; import { esc } from '../helpers.js?v=8';
import { apiFetch, toast } from '../api.js?v=7'; import { apiFetch, toast } from '../api.js?v=8';
import { modelFetch } from '../model.js?v=7'; import { modelFetch } from '../model.js?v=8';
/** /**
* Colored badge/span. * Colored badge/span.
+4 -4
View File
@@ -6,10 +6,10 @@
* avoid fighting with the main render cycle. * avoid fighting with the main render cycle.
*/ */
import { esc } from '../helpers.js?v=7'; import { esc } from '../helpers.js?v=8';
import { att_esc } from '../helpers.js?v=7'; import { att_esc } from '../helpers.js?v=8';
import { apiSubmit } from '../api.js?v=7'; import { apiSubmit } from '../api.js?v=8';
import { createDom } from '../vdom.js?v=7'; import { createDom } from '../vdom.js?v=8';
/** /**
* Render Hoover VNodes into a modal content element. * Render Hoover VNodes into a modal content element.
+8 -6
View File
@@ -5,8 +5,8 @@
* Uses the toast/dismissToast state from api.js. * Uses the toast/dismissToast state from api.js.
*/ */
import { h } from '../vdom.js?v=7'; import { h } from '../vdom.js?v=8';
import { _toasts, dismissToast } from '../api.js?v=7'; import { _toasts, dismissToast } from '../api.js?v=8';
/** /**
* Render all pending toast notifications. * Render all pending toast notifications.
@@ -23,18 +23,20 @@ export function ToastContainer() {
warning: 'toast-warning', warning: 'toast-warning',
}; };
return h('div', { class: 'toast-container' }, return h('div', { class: 'toast' },
..._toasts.map(t => ..._toasts.map(t =>
h('div', { h('div', {
class: `toast ${clsMap[t.type] || clsMap.info}`, class: `toast-message ${clsMap[t.type] || clsMap.info}`,
'on:click': () => dismissToast(t.id), 'on:click': () => dismissToast(t.id),
}, },
h('span', null, t.message), h('span', { class: 'toast-text' }, t.message),
h('div', { class: 'toast-actions' },
h('button', { h('button', {
class: 'toast-close', class: 'toast-btn toast-close',
'on:click': (e) => { e.stopPropagation(); dismissToast(t.id); }, 'on:click': (e) => { e.stopPropagation(); dismissToast(t.id); },
}, '\u00d7'), }, '\u00d7'),
), ),
), ),
),
); );
} }
+14 -14
View File
@@ -5,43 +5,43 @@
*/ */
/* ── Reactivity ──────────────────────────────────────────────── */ /* ── Reactivity ──────────────────────────────────────────────── */
export { reactive, requestUpdate } from './reactivity.js?v=7'; export { reactive, requestUpdate } from './reactivity.js?v=8';
/* ── VDOM ────────────────────────────────────────────────────── */ /* ── VDOM ────────────────────────────────────────────────────── */
export { h } from './vdom.js?v=7'; export { h } from './vdom.js?v=8';
/* ── HTM ──────────────────────────────────────────────────────── */ /* ── HTM ──────────────────────────────────────────────────────── */
export { html } from './html.js?v=7'; export { html } from './html.js?v=8';
/* ── Render ──────────────────────────────────────────────────── */ /* ── Render ──────────────────────────────────────────────────── */
export { render } from './render.js?v=7'; export { render } from './render.js?v=8';
/* ── Component ───────────────────────────────────────────────── */ /* ── Component ───────────────────────────────────────────────── */
export { definePage, hComp } from './component.js?v=7'; export { definePage, hComp } from './component.js?v=8';
/* ── Router ──────────────────────────────────────────────────── */ /* ── Router ──────────────────────────────────────────────────── */
export { createRouter, Link } from './router.js?v=7'; export { createRouter, Link } from './router.js?v=8';
/* ── WebSocket ───────────────────────────────────────────────── */ /* ── WebSocket ───────────────────────────────────────────────── */
export { connect, onMessage } from './websocket.js?v=7'; export { connect, onMessage } from './websocket.js?v=8';
/* ── API & Toast ─────────────────────────────────────────────── */ /* ── API & Toast ─────────────────────────────────────────────── */
export { apiFetch, toast, dismissToast, apiSubmit, checkAbort, poll, refactorLoad } from './api.js?v=7'; export { apiFetch, toast, dismissToast, apiSubmit, checkAbort, poll, refactorLoad } from './api.js?v=8';
/* ── Model ───────────────────────────────────────────────────── */ /* ── Model ───────────────────────────────────────────────────── */
export { modelRegister, getModel, modelFetch, collectLoadingModels } from './model.js?v=7'; export { modelRegister, getModel, modelFetch, collectLoadingModels } from './model.js?v=8';
/* ── Helpers ─────────────────────────────────────────────────── */ /* ── Helpers ─────────────────────────────────────────────────── */
export { esc, att_esc, enc, $val, parseZones, downloadBlob } from './helpers.js?v=7'; export { esc, att_esc, enc, $val, parseZones, downloadBlob } from './helpers.js?v=8';
/* ── UI Components: Layout ───────────────────────────────────── */ /* ── UI Components: Layout ───────────────────────────────────── */
export { PageHeader, renderGuard, renderGuardMulti, Tabs, SectionTitle, ActionGroup, DataTableSection } from './components/layout.js?v=7'; export { PageHeader, renderGuard, renderGuardMulti, Tabs, SectionTitle, ActionGroup, DataTableSection } from './components/layout.js?v=8';
/* ── UI Components: Data ─────────────────────────────────────── */ /* ── UI Components: Data ─────────────────────────────────────── */
export { Badge, StatusDot, Empty, Card, ConfirmDelete, Table, ActionButton, certStatusBadge, serviceStatusBadge, StatCard, StatusText, ServiceStatus, ActionCell, MonoText, ZoneSelect } from './components/data.js?v=7'; export { Badge, StatusDot, Empty, Card, ConfirmDelete, Table, ActionButton, certStatusBadge, serviceStatusBadge, StatCard, StatusText, ServiceStatus, ActionCell, MonoText, ZoneSelect } from './components/data.js?v=8';
/* ── UI Components: Modal ────────────────────────────────────── */ /* ── UI Components: Modal ────────────────────────────────────── */
export { openModal, closeModal, closeAllModals, modalVNodes, refreshModals, formModal, MultiSelectModal, QuickModal } from './components/modal.js?v=7'; export { openModal, closeModal, closeAllModals, modalVNodes, refreshModals, formModal, MultiSelectModal, QuickModal } from './components/modal.js?v=8';
/* ── UI Components: Toast ────────────────────────────────────── */ /* ── UI Components: Toast ────────────────────────────────────── */
export { ToastContainer } from './components/toast.js?v=7'; export { ToastContainer } from './components/toast.js?v=8';
+1 -1
View File
@@ -15,6 +15,6 @@
</div> </div>
<div id="modal-root"></div> <div id="modal-root"></div>
<script>window.__WS_URL__ = "__WS_URL_PLACEHOLDER__"</script> <script>window.__WS_URL__ = "__WS_URL_PLACEHOLDER__"</script>
<script type="module" src="/static/app.js?v=10"></script> <script type="module" src="/static/app.js?v=11"></script>
</body> </body>
</html> </html>
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Empty, Table, renderGuard, esc, enc, $val, apiFetch, toast, openModal, closeModal, formModal, modalVNodes, refreshModals, definePage, getModel, modelFetch, ActionCell, certStatusBadge, poll } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Empty, Table, renderGuard, esc, enc, $val, apiFetch, toast, openModal, closeModal, formModal, modalVNodes, refreshModals, definePage, getModel, modelFetch, ActionCell, certStatusBadge, poll } from '/static/hoover/index.js?v=8';
function _accountCard(account) { function _accountCard(account) {
if (!account || !account.registered) { if (!account || !account.registered) {
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, definePage, getModel, renderGuard, ServiceStatus, StatCard } from '/static/hoover/index.js?v=7'; import { html, PageHeader, definePage, getModel, renderGuard, ServiceStatus, StatCard } from '/static/hoover/index.js?v=8';
export default definePage({ export default definePage({
init() { init() {
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, h, PageHeader, ConfirmDelete, Tabs, Table, ServiceStatus, renderGuardMulti, esc, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, ActionButton, ActionGroup, QuickModal } from '/static/hoover/index.js?v=7'; import { html, h, PageHeader, ConfirmDelete, Tabs, Table, ServiceStatus, renderGuardMulti, esc, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, ActionButton, ActionGroup, QuickModal } from '/static/hoover/index.js?v=8';
function makeAddRange(activeZones, interfaces) { function makeAddRange(activeZones, interfaces) {
const opts = [ const opts = [
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Table, renderGuardMulti, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, StatusText, QuickModal, ZoneSelect } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Table, renderGuardMulti, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, StatusText, QuickModal, ZoneSelect } from '/static/hoover/index.js?v=8';
async function changeZone(name, zone, state) { async function changeZone(name, zone, state) {
const r = await apiFetch('/api/firewall/zones/' + enc(zone) + '/interfaces', { const r = await apiFetch('/api/firewall/zones/' + enc(zone) + '/interfaces', {
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Tabs, esc, definePage, renderGuard, modelFetch, getModel } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Tabs, esc, definePage, renderGuard, modelFetch, getModel } from '/static/hoover/index.js?v=8';
const logTabs = [ const logTabs = [
{ key: 'journal', label: 'Journal' }, { key: 'journal', label: 'Journal' },
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Badge, StatusDot, Card, Table, renderGuard, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, ActionButton, DataTableSection, SectionTitle, ActionGroup, QuickModal, ConfirmDelete } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Badge, StatusDot, Card, Table, renderGuard, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, ActionButton, DataTableSection, SectionTitle, ActionGroup, QuickModal, ConfirmDelete } from '/static/hoover/index.js?v=8';
const addFwd = QuickModal({ const addFwd = QuickModal({
title: 'Add Port Forward', title: 'Add Port Forward',
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, definePage } from '/static/hoover/index.js?v=7'; import { html, PageHeader, definePage } from '/static/hoover/index.js?v=8';
export default definePage({ export default definePage({
init() { init() {
+2 -2
View File
@@ -1,5 +1,5 @@
import { html, PageHeader, Badge, Empty, Table, renderGuardMulti, esc, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, ActionButton, ActionCell, ConfirmDelete, certStatusBadge, ActionGroup, QuickModal } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Badge, Empty, Table, renderGuardMulti, esc, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, ActionButton, ActionCell, ConfirmDelete, certStatusBadge, ActionGroup, QuickModal } from '/static/hoover/index.js?v=8';
import { openModal, formModal, closeModal } from '/static/hoover/components/modal.js?v=7'; import { openModal, formModal, closeModal } from '/static/hoover/components/modal.js?v=8';
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Cert lookup map from ACME state keyed by domain name // Cert lookup map from ACME state keyed by domain name
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Empty, Card, ConfirmDelete, Table, renderGuard, esc, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, MonoText, QuickModal } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Empty, Card, ConfirmDelete, Table, renderGuard, esc, enc, $val, apiFetch, toast, definePage, getModel, modelFetch, MonoText, QuickModal } from '/static/hoover/index.js?v=8';
const addRule = QuickModal({ const addRule = QuickModal({
title: 'Add Rich Rule', title: 'Add Rich Rule',
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Badge, StatusDot, Empty, Table, ServiceStatus, renderGuard, esc, enc, $val, apiFetch, toast, openModal, closeModal, formModal, definePage, getModel, modelFetch, ActionButton, ActionCell, MonoText, ActionGroup, QuickModal, downloadBlob } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Badge, StatusDot, Empty, Table, ServiceStatus, renderGuard, esc, enc, $val, apiFetch, toast, openModal, closeModal, formModal, definePage, getModel, modelFetch, ActionButton, ActionCell, MonoText, ActionGroup, QuickModal, downloadBlob } from '/static/hoover/index.js?v=8';
const addPeer = QuickModal({ const addPeer = QuickModal({
title: 'Add WireGuard Peer', title: 'Add WireGuard Peer',
+1 -1
View File
@@ -1,4 +1,4 @@
import { html, PageHeader, Badge, Empty, ConfirmDelete, renderGuard, enc, esc, $val, definePage, getModel, MultiSelectModal, QuickModal } from '/static/hoover/index.js?v=7'; import { html, PageHeader, Badge, Empty, ConfirmDelete, renderGuard, enc, esc, $val, definePage, getModel, MultiSelectModal, QuickModal } from '/static/hoover/index.js?v=8';
const addZone = QuickModal({ const addZone = QuickModal({
title: 'Add Zone', title: 'Add Zone',