PlotDirector/Docs/Codex/Notifications.md

9.5 KiB

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.

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:

@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.

Completed Word/Writer cleanup (2026-11-21)

All three web shells (application, embedded writing window, Office Companion) now load the same toast service and Word presentation adapter. word-notifications.js consumes existing native/Office presence and Writer status events; it does not fetch, poll, schedule, capture or analyse anything. requested(lease, requestId) records only a notification correlation. A manual paragraph success requires the matching request and newer verified positions; a chapter success requires the matching accepted chapter transfer. Unrelated receipts cannot claim success.

Previous presentation/message Result
Writer command paragraph, echoed into the ribbon Command diagnostics moved inside Connection and update options. Ribbon now shows concise persistent manuscript state, with full freshness explanation in its title.
Live announcements from Writer connection/command/ribbon, native sync feedback, Reader update status Removed competing routine live regions. Shared toast status/alert regions announce meaningful outcomes. Persistent text remains readable.
Changes detected / Checking changes / Synchronising chapter / Up to date Never toast or open a web alert. Incoming chapter progress is confined to persistent state/details. These exact four literals were not hard-coded web transient messages in the checked revision. Native ribbon/tray labels such as Changes found, Checking, Synchronising and Up to date remain persistent and unchanged.
Office document-message area (reading/resolving/scanning/current-scene updates and diagnostics) Moved into Manuscript details; routine updates no longer occupy the main notification area. Existing sync indicator remains visible.
Native paragraph transfer failed/cancelled, chapter Needs review One shared error/warning per failure state until accepted recovery; a warning can escalate to an error. Persistent freshness/details remain.
Manual Writer check request failure / accepted check Error toast on request failure; success toast only for matching accepted completion. Request acknowledgement/checking is silent.
Native connection dialog sync/repair request errors, timeout, accepted result Request errors/timeout toast; matching accepted manual completion uses the central adapter. Existing progress and recovery instructions remain beside the controls.
Word connection lost/restored (native and Office) Consolidated transition notifications; no initial-offline toast, no repeated reconnect warning. Embedded shell now supports these too.
Office Sync failed / Synced / Syncing... / waiting for typing Failure toast once plus visible failed status. Automatic completion clears failure silently. Explicit manual success toasts; in-progress/waiting text stays in the indicator.
Word confirmed navigation (including paragraph start), failed/expired/mismatched/timed-out navigation Shared success/error toast for the existing manual outcome; detailed command record stays inside options. Receipt processing, wait/confirmation timing and cancellation are unchanged.
Manuscript linked / structure imported / Characters created / marker save confirmed or already present Shared success toast replaces document-message completion. Binding labels, first-run step results/counts and save-required instructions remain where needed.
Scene links saved successfully / manual chapter-scene linking or ID attachment / manuscript unlinked-cleaned Shared success toast; redundant link-status completion text removed.
Manual scene-link save, chapter/scene create-link/ID attachment, first-run link/import/character creation, marker update, diagnostics scan and unlink/cleanup failures Shared error toast; actionable error details and existing recovery/confirmation workflows retained.
Reader Chapter updated / automatic checking and pending accepted updates Background completion stays silent in persistent status. Explicit Apply update success toasts. Update-read failure toasts once until recovery; persistent retry/sign-in text remains.

Retained deliberately: Word unsaved/unverified/mapping/selection/capability warnings; persistent connection/freshness/progress; first-run scan/preview/build and marker-save review instructions; detailed cleanup recovery; destructive unlink/cleanup confirmations; Context/Intent follow status and substantial unavailable-content explanations; native import conflict/review/result summaries and validation. native-companion-review.js only selects the submitted session; it has no competing notification mechanism. The native workspace connection label remains persistent and feeds the shared connection presentation. No Windows agent, VSTO ribbon, native modal maintenance/troubleshooting dialog, transport, debounce, capture, paragraph identity, navigation processing or analysis was changed.

Focused checks: shared-notifications.cjs, word-toast-outcomes.cjs, word-toast-paths.cjs (actual Razor Writer/manual check/navigation/native-dialog form paths), writer-word-notifications.cjs (existing correlated navigation timing/race regression), reader-word-freshness.cjs, and word-companion-regressions.cjs. The existing navigation test opens the newly collapsed command diagnostics before checking them; its timing/correlation assertions are retained. Office adapter tests execute the production presentation setter without starting Office. Browser and simulated standalone checks do not physically verify Word, native Windows UI, or a genuinely installed PWA.