mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 02:20:08 +08:00
- Add co-writer storage module and API router for document persistence - Restructure co-writer page to per-doc routing ([docId]) with sidebar recent list - Wire CoWriterRecent into sidebar shell and AppShellContext - Tidy notebook prompts, facade, path service, and builtin tools wiring - Refresh tests (add missing __init__.py, drop obsolete app_facade test) - Add favicon/apple-touch-icon assets and minor i18n cleanup Made-with: Cursor
29 lines
964 B
TypeScript
29 lines
964 B
TypeScript
// Lightweight client-side event bus for Co-Writer document mutations.
|
|
//
|
|
// `CoWriterRecent` (sidebar) and the home page list need to refresh whenever a
|
|
// document is created, updated (autosave), or deleted from anywhere in the
|
|
// app. We avoid a full Context provider here because the sidebar lives at the
|
|
// workspace shell level and mutations happen in disparate routes.
|
|
|
|
const EVENT_NAME = "co-writer:changed";
|
|
|
|
type Listener = () => void;
|
|
|
|
function getTarget(): EventTarget | null {
|
|
if (typeof window === "undefined") return null;
|
|
return window;
|
|
}
|
|
|
|
export function notifyCoWriterChanged(): void {
|
|
const target = getTarget();
|
|
if (!target) return;
|
|
target.dispatchEvent(new Event(EVENT_NAME));
|
|
}
|
|
|
|
export function subscribeCoWriterChanges(listener: Listener): () => void {
|
|
const target = getTarget();
|
|
if (!target) return () => {};
|
|
target.addEventListener(EVENT_NAME, listener);
|
|
return () => target.removeEventListener(EVENT_NAME, listener);
|
|
}
|