Adding some page reload debugging
This commit is contained in:
parent
51e3dd72e8
commit
bedc85e7a9
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user