diff --git a/common/spaces/disk_space_primitives.ts b/common/spaces/disk_space_primitives.ts index 8915c0b0..69bfd60c 100644 --- a/common/spaces/disk_space_primitives.ts +++ b/common/spaces/disk_space_primitives.ts @@ -86,9 +86,8 @@ export class DiskSpacePrimitives implements SpacePrimitives { name: string, encoding: FileEncoding, data: FileData, - selfUpdate?: boolean, ): Promise { - let localPath = this.filenameToPath(name); + const localPath = this.filenameToPath(name); try { // Ensure parent folder exists await Deno.mkdir(path.dirname(localPath), { recursive: true }); @@ -96,7 +95,7 @@ export class DiskSpacePrimitives implements SpacePrimitives { // Actually write the file switch (encoding) { case "string": - await Deno.writeTextFile(localPath, data as string); + await Deno.writeTextFile(`${localPath}`, data as string); break; case "dataurl": await Deno.writeFile( diff --git a/common/spaces/space.ts b/common/spaces/space.ts index add6fc3d..f1e9bb71 100644 --- a/common/spaces/space.ts +++ b/common/spaces/space.ts @@ -96,7 +96,7 @@ export class Space extends EventEmitter { async getPageMeta(name: string): Promise { let oldMeta = this.pageMetaCache.get(name); let newMeta = fileMetaToPageMeta( - await this.space.getFileMeta(`${name}.md`) + await this.space.getFileMeta(`${name}.md`), ); if (oldMeta) { if (oldMeta.lastModified !== newMeta.lastModified) { @@ -111,7 +111,7 @@ export class Space extends EventEmitter { plug: Plug, env: string, name: string, - args: any[] + args: any[], ): Promise { return this.space.invokeFunction(plug, env, name, args); } @@ -159,12 +159,12 @@ export class Space extends EventEmitter { async writePage( name: string, text: string, - selfUpdate?: boolean + selfUpdate?: boolean, ): Promise { try { this.saving = true; - let pageMeta = fileMetaToPageMeta( - await this.space.writeFile(`${name}.md`, "string", text, selfUpdate) + const pageMeta = fileMetaToPageMeta( + await this.space.writeFile(`${name}.md`, "string", text, selfUpdate), ); if (!selfUpdate) { this.emit("pageChanged", pageMeta); @@ -184,13 +184,13 @@ export class Space extends EventEmitter { async fetchAttachmentList(): Promise { return (await this.space.fetchFileList()).filter( (fileMeta) => - !fileMeta.name.endsWith(".md") && !fileMeta.name.endsWith(".plug.json") + !fileMeta.name.endsWith(".md") && !fileMeta.name.endsWith(".plug.json"), ); } readAttachment( name: string, - encoding: FileEncoding + encoding: FileEncoding, ): Promise<{ data: FileData; meta: AttachmentMeta }> { return this.space.readFile(name, encoding); } @@ -203,7 +203,7 @@ export class Space extends EventEmitter { name: string, encoding: FileEncoding, data: FileData, - selfUpdate?: boolean | undefined + selfUpdate?: boolean | undefined, ): Promise { return this.space.writeFile(name, encoding, data, selfUpdate); } diff --git a/plugs/query/materialized_queries.ts b/plugs/query/materialized_queries.ts index 8b686b35..f1da7c75 100644 --- a/plugs/query/materialized_queries.ts +++ b/plugs/query/materialized_queries.ts @@ -28,6 +28,7 @@ export async function updateMaterializedQueriesCommand() { currentPage, ) ) { + console.log("Going reload the page"); await reloadPage(); } } @@ -35,7 +36,7 @@ export async function updateMaterializedQueriesCommand() { export const templateInstRegex = /()(.+?)()/gs; -async function updateTemplateInstantiations( +function updateTemplateInstantiations( text: string, pageName: string, ): Promise { @@ -81,11 +82,19 @@ async function updateTemplateInstantiations( ); } -async function cleanTemplateInstantiations(text: string): Promise { +function cleanTemplateInstantiations(text: string): Promise { return replaceAsync( text, templateInstRegex, - async (fullMatch, startInst, type, template, args, body, endInst) => { + ( + fullMatch, + startInst, + type, + template, + args, + body, + endInst, + ): Promise => { if (type === "use") { body = body.replaceAll( queryRegex, @@ -99,7 +108,7 @@ async function cleanTemplateInstantiations(text: string): Promise { }, ); } - return `${startInst}${body}${endInst}`; + return Promise.resolve(`${startInst}${body}${endInst}`); }, ); } @@ -108,6 +117,7 @@ async function cleanTemplateInstantiations(text: string): Promise { export async function updateMaterializedQueriesOnPage( pageName: string, ): Promise { + // console.log("Updating queries"); let text = ""; try { text = (await readPage(pageName)).text; diff --git a/web/editor.tsx b/web/editor.tsx index 5a6b0211..9f867a47 100644 --- a/web/editor.tsx +++ b/web/editor.tsx @@ -582,12 +582,10 @@ export class Editor { return actualResult; } - reloadPage() { + async reloadPage() { console.log("Reloading page"); - safeRun(async () => { - clearTimeout(this.saveTimeout); - await this.loadPage(this.currentPage!); - }); + clearTimeout(this.saveTimeout); + await this.loadPage(this.currentPage!); } focus() { @@ -614,7 +612,9 @@ export class Editor { if (previousPage) { this.saveState(previousPage); this.space.unwatchPage(previousPage); - await this.save(true); + if (previousPage !== pageName) { + await this.save(true); + } } this.viewDispatch({ diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index 5466a833..a69d17d2 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -51,7 +51,7 @@ export function editorSyscalls(editor: Editor): SysCallMapping { ) => { await editor.navigate(name, pos, replaceState); }, - "editor.reloadPage": async (ctx) => { + "editor.reloadPage": async () => { await editor.reloadPage(); }, "editor.openUrl": async (ctx, url: string) => {