Standardize shared toast feedback and consolidate transient notifications
This commit is contained in:
parent
0a1bfc0960
commit
23f3f442d7
@ -59,6 +59,10 @@ For broad tasks, identify the primary implementation path first. Expand discover
|
||||
|
||||
Parallel tool calls are useful for latency but must not be used to load large amounts of speculative context simultaneously.
|
||||
|
||||
## UI Notifications
|
||||
|
||||
Use the shared `PlotDirector.toast` service for transient feedback. See `Docs/Codex/Notifications.md` for the API, partial-view usage, and messages that must remain inline. Do not introduce another notification library or page-specific toast host.
|
||||
|
||||
## Build And Test
|
||||
|
||||
Normal build gate:
|
||||
|
||||
42
Docs/Codex/Notifications.md
Normal file
42
Docs/Codex/Notifications.md
Normal file
@ -0,0 +1,42 @@
|
||||
# Shared UI notifications
|
||||
|
||||
The application shell loads `wwwroot/js/notifications.js` and `css/notifications.css` once, outside replaceable page/panel content. No additional library is required.
|
||||
|
||||
```js
|
||||
PlotDirector.toast.success('Changes saved');
|
||||
PlotDirector.toast.info('Export completed');
|
||||
PlotDirector.toast.warning('Word connection interrupted');
|
||||
PlotDirector.toast.error('Unable to save changes');
|
||||
```
|
||||
|
||||
Use success for completed user actions, info for meaningful background completion, warning for attention required, and error for unsuccessful operations. Routine successful background sync, paragraph changes and navigation should stay silent. Keep progress indicators, field validation, destructive confirmations, persistent connection state, and substantial recovery instructions in their existing workflow.
|
||||
|
||||
Success/info dismiss after six seconds. Warning/error remain until dismissed. An optional second argument `{ duration: 10000 }` overrides the duration; zero means manual dismissal. The returned function dismisses that toast. Hover/focus pauses auto dismissal; leaving restarts the duration. Close buttons work with the keyboard and Escape dismisses the focused toast. Notifications never take focus. Status/alert roles announce messages; labels convey categories without relying on colour.
|
||||
|
||||
Identical category/text is suppressed while visible and for five seconds after its last accepted display. At most four toasts appear; the oldest is removed on overflow. This is transient feedback, never the sole record of an ongoing problem.
|
||||
|
||||
Pages and dynamically loaded partial scripts use the same API without creating hosts or subscriptions. For server flash messages, retain the existing consuming TempData read and emit Razor-encoded text:
|
||||
|
||||
```cshtml
|
||||
@if (TempData["SaveMessage"] is string message)
|
||||
{
|
||||
<span hidden data-toast-message="success">@message</span>
|
||||
}
|
||||
```
|
||||
|
||||
The singleton observer consumes and removes markers, including newly inserted partials. Do not use `TempData.Peek`/`Keep` for these messages or cache/reinsert consumed flash fragments. Messages are plain text, never HTML. The service and CSS use the same shell in browser and installed PWA, including viewport/safe-area sizing and theme variables.
|
||||
|
||||
## Bounded migration inventory
|
||||
|
||||
- Shared archive/import information; book archive/manuscript information; chapter archive/update messages.
|
||||
- Character image success, relationship/update information; location list/detail success; floor plan and metric messages; collaborator success; native review save confirmation.
|
||||
- Word: one interruption warning after a connected session, one recovery info message; explicit sync-request errors also surface as toasts, retaining detailed inline feedback. The separately hosted Office Companion loads the same service and reports a sync failure once until recovery. No initial-offline warning and no routine successful sync/navigation toast.
|
||||
- Retained: archive/location/image/collaboration errors and recovery instructions; Word persistent status and sync progress/review instructions; onboarding and import-result workflows; scenario warnings; all validation and confirmation dialogs.
|
||||
|
||||
Other feature-specific/admin banners and scripts remain future cleanup opportunities. Do not broaden migration without reviewing their workflow semantics.
|
||||
|
||||
## Focused verification
|
||||
|
||||
Run `node PlotLine.Tests/Browser/shared-notifications.cjs` from the repository root. It uses production assets in isolated Chromium documents with no application/database writes, testing all categories, plain-text rendering, focus preservation, bounded display, dismissal, duplicate suppression, partial markers and repeated script loading, and native Word interruption/recovery events. Both ordinary and simulated standalone presentation are covered; physical installed-PWA and Word acceptance are separate from this check.
|
||||
|
||||
Implementation validation (2026-11-21): solution build and the full executable regression harness passed; focused browser checks passed. Word transport, debounce, capture, paragraph identity, navigation, and native Windows components were not changed.
|
||||
57
PlotLine.Tests/Browser/shared-notifications.cjs
Normal file
57
PlotLine.Tests/Browser/shared-notifications.cjs
Normal file
@ -0,0 +1,57 @@
|
||||
// Isolated production assets: no database or manuscript activity.
|
||||
const { chromium } = require('playwright');
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const assets = path.resolve(__dirname, '../../PlotLine/wwwroot');
|
||||
(async () => {
|
||||
const browser = await chromium.launch();
|
||||
try {
|
||||
for (const standalone of [false, true]) {
|
||||
const page = await browser.newPage({ viewport: { width: 390, height: 844 } });
|
||||
await page.setContent('<input id="editor"><div data-toast-host class="pd-toast-host" aria-label="Notifications"></div><main id="panel"></main>');
|
||||
await page.evaluate(value => Object.defineProperty(navigator, 'standalone', { value }), standalone);
|
||||
await page.addStyleTag({ path: assets + '/css/notifications.css' });
|
||||
await page.addScriptTag({ path: assets + '/js/notifications.js' });
|
||||
await page.locator('#editor').focus();
|
||||
await page.evaluate(() => { for (const type of ['success','info','warning','error']) PlotDirector.toast[type]('<b>' + type + '</b>'); });
|
||||
assert.equal(await page.locator('.pd-toast').count(), 4);
|
||||
assert.equal(await page.locator('.pd-toast b').count(), 0, 'text is never HTML');
|
||||
assert.equal(await page.locator('[role=alert]').count(), 2);
|
||||
assert.equal(await page.locator('[role=status]').count(), 2);
|
||||
assert(await page.locator('#editor').evaluate(n => n === document.activeElement));
|
||||
await page.evaluate(() => PlotDirector.toast.error('<b>error</b>'));
|
||||
assert.equal(await page.locator('.pd-toast').count(), 4);
|
||||
await page.evaluate(() => PlotDirector.toast.info('overflow'));
|
||||
assert.equal(await page.locator('.pd-toast').count(), 4);
|
||||
assert.equal(await page.getByText('<b>success</b>', { exact: true }).count(), 0);
|
||||
await page.locator('.pd-toast button').first().focus(); await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('.pd-toast').count(), 3);
|
||||
await page.locator('.pd-toast button').first().click();
|
||||
await page.evaluate(() => document.querySelectorAll('.pd-toast button').forEach(b => b.click()));
|
||||
await page.mouse.move(0, 800);
|
||||
await page.locator('#editor').focus();
|
||||
await page.evaluate(() => PlotDirector.toast.success('short', { duration: 80 }));
|
||||
await page.waitForTimeout(180); assert.equal(await page.locator('.pd-toast').count(), 0);
|
||||
await page.evaluate(() => document.querySelector('#panel').innerHTML = '<span hidden data-toast-message="success">Saved partial</span>');
|
||||
await page.locator('.pd-toast').filter({ hasText: 'Saved partial' }).waitFor();
|
||||
await page.addScriptTag({ path: assets + '/js/notifications.js' });
|
||||
await page.evaluate(() => document.querySelector('#panel').innerHTML = '<span hidden data-toast-message="success">Saved partial</span>');
|
||||
await page.waitForTimeout(50);
|
||||
assert.equal(await page.locator('[data-toast-host]').count(), 1);
|
||||
assert.equal(await page.locator('.pd-toast').count(), 1);
|
||||
assert.equal(await page.locator('[data-toast-message]').count(), 0);
|
||||
await page.addScriptTag({ path: assets + '/js/word-notifications.js' });
|
||||
await page.addScriptTag({ path: assets + '/js/word-notifications.js' });
|
||||
const presence = value => page.evaluate(value => dispatchEvent(new CustomEvent('native-companion-presence', { detail: value ? [{ wordAvailable: true }] : [] })), value);
|
||||
await presence(false); assert.equal(await page.locator('.pd-toast--warning').count(), 0);
|
||||
await presence(true); await presence(true); await presence(false); await presence(false);
|
||||
assert.equal(await page.locator('.pd-toast--warning').count(), 1);
|
||||
await presence(true); assert.equal(await page.locator('.pd-toast--warning').count(), 0);
|
||||
assert.equal(await page.locator('.pd-toast--info').count(), 1);
|
||||
const bounds = await page.locator('[data-toast-host]').boundingBox();
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= 390);
|
||||
console.log('PASS shared notifications: categories, safe text, focus, bounds, dedup, dismissal, partials, singleton, Word transitions; standalone=' + standalone);
|
||||
await page.close();
|
||||
}
|
||||
} finally { await browser.close(); }
|
||||
})().catch(e => { console.error(e); process.exitCode = 1; });
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
@if (TempData["ArchiveMessage"] is string archiveMessage)
|
||||
{
|
||||
<div class="alert alert-info">@archiveMessage</div>
|
||||
<span hidden data-toast-message="info">@archiveMessage</span>
|
||||
}
|
||||
@if (TempData["ArchiveError"] is string archiveError)
|
||||
{
|
||||
@ -24,7 +24,7 @@
|
||||
}
|
||||
@if (TempData["ManuscriptMessage"] is string manuscriptMessage)
|
||||
{
|
||||
<div class="alert alert-info">@manuscriptMessage</div>
|
||||
<span hidden data-toast-message="info">@manuscriptMessage</span>
|
||||
}
|
||||
|
||||
<div data-pwa-header class="page-heading">
|
||||
|
||||
@ -17,11 +17,11 @@
|
||||
|
||||
@if (TempData["ArchiveMessage"] is string archiveMessage)
|
||||
{
|
||||
<div class="alert alert-info">@archiveMessage</div>
|
||||
<span hidden data-toast-message="info">@archiveMessage</span>
|
||||
}
|
||||
@if (TempData["ChapterMessage"] is string chapterMessage)
|
||||
{
|
||||
<div class="alert alert-info">@chapterMessage</div>
|
||||
<span hidden data-toast-message="info">@chapterMessage</span>
|
||||
}
|
||||
|
||||
<div data-pd-context="chapter" data-pd-context-id="@Model.Chapter.ChapterID" data-pd-context-label="@Model.Chapter.ChapterTitle" data-pwa-task class="page-heading">
|
||||
|
||||
@ -86,7 +86,7 @@
|
||||
|
||||
@if (TempData["ImageMessage"] is string imageMessage)
|
||||
{
|
||||
<div class="alert alert-success">@imageMessage</div>
|
||||
<span hidden data-toast-message="success">@imageMessage</span>
|
||||
}
|
||||
@if (TempData["ImageError"] is string imageError)
|
||||
{
|
||||
@ -94,11 +94,11 @@
|
||||
}
|
||||
@if (TempData["RelationshipMessage"] is string relationshipMessage)
|
||||
{
|
||||
<div class="alert alert-info">@relationshipMessage</div>
|
||||
<span hidden data-toast-message="info">@relationshipMessage</span>
|
||||
}
|
||||
@if (TempData["CharacterMessage"] is string characterMessage)
|
||||
{
|
||||
<div class="alert alert-info">@characterMessage</div>
|
||||
<span hidden data-toast-message="info">@characterMessage</span>
|
||||
}
|
||||
|
||||
<section id="character-overview" class="asset-detail-grid">
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
@if (TempData["FloorPlanMessage"] is string message)
|
||||
{
|
||||
<div class="alert alert-success">@message</div>
|
||||
<span hidden data-toast-message="success">@message</span>
|
||||
}
|
||||
|
||||
<section class="edit-panel">
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
|
||||
@if (TempData["LocationMessage"] is string locationMessage)
|
||||
{
|
||||
<div class="alert alert-info">@locationMessage</div>
|
||||
<span hidden data-toast-message="info">@locationMessage</span>
|
||||
}
|
||||
|
||||
<section class="edit-panel">
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
@if (TempData["LocationMessage"] is string message)
|
||||
{
|
||||
<div class="alert alert-success" role="status">@message</div>
|
||||
<span hidden data-toast-message="success">@message</span>
|
||||
}
|
||||
@if (TempData["LocationError"] is string error)
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<a href="/native-companion/workspace?bookId=@Model.Row.BookID">← Companion workspace and other chapters</a>
|
||||
<h1 class="h3 mt-3">@(string.IsNullOrWhiteSpace(Model.Result.ChapterTitle)?"Chapter scene review":Model.Result.ChapterTitle)</h1>
|
||||
<p>AI scene suggestions · Word remains authoritative. Edit, approve or reject below. Saving decisions does not import scenes, change prose or overwrite existing story data.</p>
|
||||
@if(TempData["NativeReviewSaved"] is string message){<div class="alert alert-success" role="status">@message</div>}
|
||||
@if(TempData["NativeReviewSaved"] is string message){<span hidden data-toast-message="success">@message</span>}
|
||||
<form method="post" action="/native-companion/reviews/@Model.Row.ReviewID">
|
||||
@Html.AntiForgeryToken()<input type="hidden" name="version" value="@Model.Row.Version" />
|
||||
@for(var i=0;i<Model.Result.Scenes.Length;i++){var scene=Model.Result.Scenes[i];var decision=Model.Decisions.FirstOrDefault(d=>d.Index==i);
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
@if (TempData["CollaborationMessage"] is string collaborationMessage)
|
||||
{
|
||||
<div class="alert alert-success">@collaborationMessage</div>
|
||||
<span hidden data-toast-message="success">@collaborationMessage</span>
|
||||
}
|
||||
|
||||
@if (TempData["CollaborationError"] is string collaborationError)
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
@if (TempData["ProjectMetricMessage"] is string message)
|
||||
{
|
||||
<div class="alert alert-info">@message</div>
|
||||
<span hidden data-toast-message="info">@message</span>
|
||||
}
|
||||
|
||||
<section class="story-bible-section">
|
||||
|
||||
@ -115,6 +115,7 @@
|
||||
<script type="importmap"></script>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/notifications.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/plotline-theme.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/context-panels.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/onboarding.css" asp-append-version="true" />
|
||||
@ -277,7 +278,7 @@
|
||||
<main data-pwa-page-content role="main" class="pb-3">
|
||||
@if (TempData["ArchiveMessage"] is string archiveMessage)
|
||||
{
|
||||
<div class="alert alert-info">@archiveMessage</div>
|
||||
<span hidden data-toast-message="info">@archiveMessage</span>
|
||||
}
|
||||
@if (TempData["ArchiveError"] is string archiveError)
|
||||
{
|
||||
@ -285,7 +286,7 @@
|
||||
}
|
||||
@if (TempData["ImportMessage"] is string importMessage)
|
||||
{
|
||||
<div class="alert alert-info">@importMessage</div>
|
||||
<span hidden data-toast-message="info">@importMessage</span>
|
||||
}
|
||||
@RenderBody()
|
||||
</main>
|
||||
@ -336,6 +337,8 @@
|
||||
}
|
||||
|
||||
<partial name="_ConfirmationDialog" />
|
||||
<div class="pd-toast-host" data-toast-host aria-label="Notifications"></div>
|
||||
<script src="~/js/notifications.js" asp-append-version="true"></script>
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
@ -359,6 +362,7 @@
|
||||
<script src="~/js/application-shell.js" asp-append-version="true"></script>
|
||||
}
|
||||
<script src="~/js/writer-word.js" asp-append-version="true" defer></script>
|
||||
<script src="~/js/word-notifications.js" asp-append-version="true"></script>
|
||||
<script src="~/js/native-companion-status.js" asp-append-version="true" defer></script>
|
||||
<script src="~/js/word-companion-presence.js" asp-append-version="true"></script>
|
||||
<script src="~/js/story-intelligence-global-progress.js" asp-append-version="true"></script>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>PlotDirector Companion</title>
|
||||
<link rel="stylesheet" href="~/css/word-companion.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/notifications.css" asp-append-version="true" />
|
||||
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
@ -617,6 +618,8 @@
|
||||
{
|
||||
<script src="https://cdn.jsdelivr.net/npm/@@microsoft/signalr@8.0.7/dist/browser/signalr.min.js"></script>
|
||||
}
|
||||
<div class="pd-toast-host" data-toast-host aria-label="Notifications"></div>
|
||||
<script src="~/js/notifications.js" asp-append-version="true"></script>
|
||||
<script src="~/js/word-companion-host.js" asp-append-version="true"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
11
PlotLine/wwwroot/css/notifications.css
Normal file
11
PlotLine/wwwroot/css/notifications.css
Normal file
@ -0,0 +1,11 @@
|
||||
.pd-toast-host { position: fixed; z-index: 1090; top: max(1rem, env(safe-area-inset-top)); right: max(1rem, env(safe-area-inset-right)); width: min(26rem, calc(100vw - 2rem)); display: grid; gap: .65rem; pointer-events: none; max-height: calc(100dvh - 2rem); overflow-y: auto; }
|
||||
.pd-toast { display: flex; align-items: start; gap: .75rem; padding: .9rem 1rem; border: 1px solid var(--bs-border-color, #888); border-left: .3rem solid var(--toast-accent); border-radius: .5rem; background: var(--plotline-surface-elevated, var(--bs-body-bg, white)); color: var(--plotline-text, var(--bs-body-color, #212529)); box-shadow: 0 .25rem 1rem #0003; pointer-events: auto; overflow-wrap: anywhere; }
|
||||
.pd-toast--success { --toast-accent: #198754; }
|
||||
.pd-toast--info { --toast-accent: #0d6efd; }
|
||||
.pd-toast--warning { --toast-accent: #b58100; }
|
||||
.pd-toast--error { --toast-accent: #dc3545; }
|
||||
.pd-toast > span { flex: 1; }
|
||||
.pd-toast button { border: 0; background: transparent; color: inherit; font-size: 1.4rem; line-height: 1; padding: .1rem .25rem; }
|
||||
.pd-toast button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
|
||||
|
||||
.pd-toast-region { display: contents; }
|
||||
@ -15,7 +15,7 @@
|
||||
try{const response=await fetch((event.submitter?.hasAttribute('formaction')?event.submitter.formAction:syncForm.action),{method:'POST',body,headers:{'X-Requested-With':'XMLHttpRequest'},signal:AbortSignal.timeout(15000)});
|
||||
if(response.redirected||!response.headers.get('content-type')?.includes('application/json'))throw Error('Sign in to PlotDirector again before requesting synchronisation.');
|
||||
const result=await response.json();if(!response.ok)throw Error(result.message||'Synchronisation could not be requested.');syncFeedback.textContent=result.message;if(syncPending)syncPending.requestId=result.requestId&&result.requestId!=='00000000-0000-0000-0000-000000000000'?result.requestId:null;if(!syncPending?.requestId){syncPending=null;syncButton.disabled=false;}void update();
|
||||
}catch(error){syncPending=null;syncButton.disabled=false;syncFeedback.textContent=error.message||'Could not contact PlotDirector. Your saved manuscript is unchanged.';}
|
||||
}catch(error){syncPending=null;syncButton.disabled=false;syncFeedback.textContent=error.message||'Could not contact PlotDirector. Your saved manuscript is unchanged.';window.PlotDirector?.toast?.error(syncFeedback.textContent);}
|
||||
});
|
||||
root.addEventListener('click',()=>details?.showModal());
|
||||
details?.querySelector('[data-close-word-details]')?.addEventListener('click',()=>details.close());
|
||||
|
||||
62
PlotLine/wwwroot/js/notifications.js
Normal file
62
PlotLine/wwwroot/js/notifications.js
Normal file
@ -0,0 +1,62 @@
|
||||
// Shared shell service: safe to call from pages and refreshed partials.
|
||||
(() => {
|
||||
const pd = window.PlotDirector ||= {};
|
||||
if (pd.toast) return;
|
||||
const host = document.querySelector('[data-toast-host]');
|
||||
if (!host) return;
|
||||
const regions = {};
|
||||
for (const priority of ['polite', 'assertive']) {
|
||||
const region = document.createElement('div');
|
||||
region.className = 'pd-toast-region';
|
||||
region.setAttribute('aria-live', priority);
|
||||
region.setAttribute('aria-relevant', 'additions');
|
||||
host.append(region);
|
||||
regions[priority] = region;
|
||||
}
|
||||
const active = new Map(), recent = new Map();
|
||||
const labels = { success: 'Success', info: 'Information', warning: 'Warning', error: 'Error' };
|
||||
function show(type, message, options = {}) {
|
||||
message = String(message ?? '').trim();
|
||||
if (!message) return;
|
||||
const key = type + ':' + message, now = Date.now();
|
||||
if (active.has(key) || now - (recent.get(key) || 0) < 5000) return;
|
||||
for (const [entry, time] of recent) if (now - time >= 5000) recent.delete(entry);
|
||||
recent.set(key, now);
|
||||
if (active.size >= 4) active.values().next().value();
|
||||
const node = document.createElement('div');
|
||||
node.className = 'pd-toast pd-toast--' + type;
|
||||
node.setAttribute('role', type === 'error' || type === 'warning' ? 'alert' : 'status');
|
||||
node.setAttribute('aria-atomic', 'true');
|
||||
const content = document.createElement('span');
|
||||
const label = document.createElement('strong');
|
||||
label.textContent = labels[type] + ': ';
|
||||
content.append(label, document.createTextNode(message));
|
||||
const close = document.createElement('button');
|
||||
close.type = 'button'; close.textContent = '×';
|
||||
close.setAttribute('aria-label', 'Dismiss ' + labels[type].toLowerCase() + ' notification');
|
||||
let timer;
|
||||
const dismiss = () => { clearTimeout(timer); node.remove(); active.delete(key); };
|
||||
close.addEventListener('click', dismiss);
|
||||
node.addEventListener('keydown', event => { if (event.key === 'Escape') dismiss(); });
|
||||
node.append(content, close); regions[type === 'error' || type === 'warning' ? 'assertive' : 'polite'].append(node); active.set(key, dismiss);
|
||||
const duration = options.duration ?? (type === 'error' || type === 'warning' ? 0 : 6000);
|
||||
const start = () => { clearTimeout(timer); if (duration > 0) timer = setTimeout(dismiss, duration); };
|
||||
node.addEventListener('mouseenter', () => clearTimeout(timer));
|
||||
node.addEventListener('focusin', () => clearTimeout(timer));
|
||||
node.addEventListener('mouseleave', () => { if (!node.contains(document.activeElement)) start(); });
|
||||
node.addEventListener('focusout', () => { if (!node.matches(':hover')) start(); });
|
||||
start();
|
||||
return dismiss;
|
||||
}
|
||||
pd.toast = Object.fromEntries(Object.keys(labels).map(type => [type, (message, options) => show(type, message, options)]));
|
||||
// Consume encoded server flash markers once, including markers inserted by partial refreshes.
|
||||
function consume() {
|
||||
document.querySelectorAll('[data-toast-message]').forEach(node => {
|
||||
const type = node.dataset.toastMessage;
|
||||
if (Object.hasOwn(labels, type)) pd.toast[type](node.textContent);
|
||||
node.remove();
|
||||
});
|
||||
}
|
||||
consume();
|
||||
new MutationObserver(consume).observe(document.body, { childList: true, subtree: true });
|
||||
})();
|
||||
@ -612,8 +612,18 @@
|
||||
});
|
||||
};
|
||||
|
||||
let syncFailureNotified = false;
|
||||
let dismissSyncWarning;
|
||||
const setSyncStatus = (message) => {
|
||||
setText(syncStatus, message);
|
||||
if (message === "Sync failed" && !syncFailureNotified) {
|
||||
syncFailureNotified = true;
|
||||
dismissSyncWarning = window.PlotDirector?.toast?.error("Word synchronisation failed. Check Companion diagnostics before retrying.");
|
||||
} else if (message === "Synced" && syncFailureNotified) {
|
||||
syncFailureNotified = false;
|
||||
dismissSyncWarning?.();
|
||||
window.PlotDirector?.toast?.info("Word synchronisation restored.");
|
||||
}
|
||||
};
|
||||
|
||||
const setStructurePreviewStatus = (message) => {
|
||||
|
||||
20
PlotLine/wwwroot/js/word-notifications.js
Normal file
20
PlotLine/wwwroot/js/word-notifications.js
Normal file
@ -0,0 +1,20 @@
|
||||
// Presentation only. Observe existing presence events; never request or schedule Word work.
|
||||
(() => {
|
||||
if (window.PlotDirector.wordNotifications) return;
|
||||
window.PlotDirector.wordNotifications = true;
|
||||
let connected = false, interrupted = false, dismissWarning;
|
||||
window.addEventListener('native-companion-presence', event => {
|
||||
const leases = event.detail;
|
||||
if (!Array.isArray(leases)) return;
|
||||
const available = leases.some(lease => lease.wordAvailable);
|
||||
if (connected && !available && !interrupted) {
|
||||
interrupted = true;
|
||||
dismissWarning = window.PlotDirector.toast.warning('Word connection interrupted. Saved scenes remain available; check the Word connection indicator.');
|
||||
} else if (interrupted && available) {
|
||||
interrupted = false;
|
||||
dismissWarning?.();
|
||||
window.PlotDirector.toast.info('Word connection restored.');
|
||||
}
|
||||
connected = available;
|
||||
});
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user