1
0

Adding some page reload debugging

This commit is contained in:
Zef Hemel 2023-11-12 10:33:27 +01:00
parent 51e3dd72e8
commit bedc85e7a9
3 changed files with 26 additions and 14 deletions

View File

@ -96,8 +96,8 @@ export class EventedSpacePrimitives implements SpacePrimitives {
} }
this.spaceSnapshot[name] = newMeta.lastModified; this.spaceSnapshot[name] = newMeta.lastModified;
// This can happen async
if (name.endsWith(".md")) { if (name.endsWith(".md")) {
// Let's trigger some page-specific events
const pageName = name.substring(0, name.length - 3); const pageName = name.substring(0, name.length - 3);
let text = ""; let text = "";
const decoder = new TextDecoder("utf-8"); const decoder = new TextDecoder("utf-8");
@ -114,9 +114,9 @@ export class EventedSpacePrimitives implements SpacePrimitives {
triggerEventsAndCache(name: string, newHash: number) { triggerEventsAndCache(name: string, newHash: number) {
const oldHash = this.spaceSnapshot[name]; const oldHash = this.spaceSnapshot[name];
if (oldHash && oldHash !== newHash) { if (oldHash && newHash && oldHash !== newHash) {
// Page changed since last cached metadata, trigger event // 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; this.spaceSnapshot[name] = newHash;
return; return;

View File

@ -128,7 +128,6 @@ export class ServerSystem {
eventHook.addLocalListener("file:changed", (path, localChange) => { eventHook.addLocalListener("file:changed", (path, localChange) => {
(async () => { (async () => {
// console.log("!!!!! FILE CHANGED", path, localChange);
if (!localChange && path.endsWith(".md")) { if (!localChange && path.endsWith(".md")) {
const pageName = path.slice(0, -3); const pageName = path.slice(0, -3);
const data = await this.spacePrimitives.readFile(path); const data = await this.spacePrimitives.readFile(path);

View File

@ -389,16 +389,29 @@ export class Client {
this.eventHook, this.eventHook,
); );
this.eventHook.addLocalListener("file:changed", (path: string) => { this.eventHook.addLocalListener(
// Only reload when watching the current page (to avoid reloading when switching pages) "file:changed",
if ( (
this.space.watchInterval && `${this.currentPage}.md` === path path: string,
) { _localChange?: boolean,
console.log("Page changed elsewhere, reloading"); oldHash?: number,
this.flashNotification("Page changed elsewhere, reloading"); newHash?: number,
this.reloadPage(); ) => {
} // 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.eventHook.addLocalListener("file:listed", (fileList: FileMeta[]) => {
this.ui.viewDispatch({ this.ui.viewDispatch({