diff --git a/common/spaces/evented_space_primitives.ts b/common/spaces/evented_space_primitives.ts index 6168331..def2a0e 100644 --- a/common/spaces/evented_space_primitives.ts +++ b/common/spaces/evented_space_primitives.ts @@ -96,8 +96,8 @@ export class EventedSpacePrimitives implements SpacePrimitives { } this.spaceSnapshot[name] = newMeta.lastModified; - // This can happen async if (name.endsWith(".md")) { + // Let's trigger some page-specific events const pageName = name.substring(0, name.length - 3); let text = ""; const decoder = new TextDecoder("utf-8"); @@ -114,9 +114,9 @@ export class EventedSpacePrimitives implements SpacePrimitives { triggerEventsAndCache(name: string, newHash: number) { const oldHash = this.spaceSnapshot[name]; - if (oldHash && oldHash !== newHash) { + if (oldHash && newHash && oldHash !== newHash) { // Page changed since last cached metadata, trigger event - this.dispatchEvent("file:changed", name); + this.dispatchEvent("file:changed", name, false, oldHash, newHash); } this.spaceSnapshot[name] = newHash; return; diff --git a/server/server_system.ts b/server/server_system.ts index ff231e6..0f67b0f 100644 --- a/server/server_system.ts +++ b/server/server_system.ts @@ -128,7 +128,6 @@ export class ServerSystem { eventHook.addLocalListener("file:changed", (path, localChange) => { (async () => { - // console.log("!!!!! FILE CHANGED", path, localChange); if (!localChange && path.endsWith(".md")) { const pageName = path.slice(0, -3); const data = await this.spacePrimitives.readFile(path); diff --git a/web/client.ts b/web/client.ts index 1bb6bf8..4d572cd 100644 --- a/web/client.ts +++ b/web/client.ts @@ -389,16 +389,29 @@ export class Client { this.eventHook, ); - this.eventHook.addLocalListener("file:changed", (path: string) => { - // Only reload when watching the current page (to avoid reloading when switching pages) - if ( - this.space.watchInterval && `${this.currentPage}.md` === path - ) { - console.log("Page changed elsewhere, reloading"); - this.flashNotification("Page changed elsewhere, reloading"); - this.reloadPage(); - } - }); + this.eventHook.addLocalListener( + "file:changed", + ( + path: string, + _localChange?: boolean, + oldHash?: number, + newHash?: number, + ) => { + // Only reload when watching the current page (to avoid reloading when switching pages) + if ( + this.space.watchInterval && `${this.currentPage}.md` === path + ) { + console.log( + "Page changed elsewhere, reloading. Old hash", + oldHash, + "new hash", + newHash, + ); + this.flashNotification("Page changed elsewhere, reloading"); + this.reloadPage(); + } + }, + ); this.eventHook.addLocalListener("file:listed", (fileList: FileMeta[]) => { this.ui.viewDispatch({