Avoid builtin page attributes to be overridden

This commit is contained in:
Zef Hemel
2023-12-22 11:27:07 +01:00
parent 8577fb95db
commit 82391682f6
11 changed files with 38 additions and 48 deletions
+1 -10
View File
@@ -235,7 +235,7 @@ export class Client {
// console.log("Operations", operations);
if (operations > 0) {
// Update the page list
await this.space.updatePageList();
await this.space.updatePageListCache();
}
if (operations !== undefined) {
// "sync:success" is called with a number of operations only from syncSpace(), not from syncing individual pages
@@ -499,15 +499,6 @@ export class Client {
},
);
// this.eventHook.addLocalListener("file:listed", (fileList: FileMeta[]) => {
// this.ui.viewDispatch({
// type: "update-all-pages",
// pages: fileList.filter(this.space.isListedPage).map(
// fileMetaToPageMeta,
// ),
// });
// });
this.space.watch();
return localSpacePrimitives;
+1 -18
View File
@@ -140,23 +140,6 @@ export class ClientSystem {
}
},
);
// Debugging
// this.eventHook.addLocalListener("file:listed", (files) => {
// console.log("New file list", files);
// });
// this.eventHook.addLocalListener("file:changed", (file) => {
// console.log("File changed", file);
// });
// this.eventHook.addLocalListener("file:created", (file) => {
// console.log("File created", file);
// });
// this.eventHook.addLocalListener("file:deleted", (file) => {
// console.log("File deleted", file);
// });
}
async init() {
@@ -205,7 +188,7 @@ export class ClientSystem {
async reloadPlugsFromSpace(space: Space) {
console.log("Loading plugs");
await space.updatePageList();
// await space.updatePageList();
await this.system.unloadAll();
console.log("(Re)loading plugs");
await Promise.all((await space.listPlugs()).map(async (plugMeta) => {
+4
View File
@@ -23,6 +23,10 @@ export function PageNavigator({
}) {
const options: FilterOption[] = [];
for (const pageMeta of allPages) {
// Sanitize the page name
if (!pageMeta.name) {
pageMeta.name = pageMeta.ref;
}
// Order by last modified date in descending order
let orderId = -new Date(pageMeta.lastModified).getTime();
// Unless it was opened in this session
+14 -11
View File
@@ -13,7 +13,9 @@ const pageWatchInterval = 5000;
export class Space {
imageHeightCache = new LimitedMap<number>(100); // url -> height
widgetHeightCache = new LimitedMap<number>(100); // bodytext -> height
cachedPageList: PageMeta[] = [];
// Note: this is "clean" PageMeta, it doesn't contain custom attributes (it's fetched from the store)
private cachedPageList: PageMeta[] = [];
debouncedImageCacheFlush = throttle(() => {
this.ds.set(["cache", "imageHeight"], this.imageHeightCache).catch(
@@ -57,7 +59,7 @@ export class Space {
constructor(
readonly spacePrimitives: SpacePrimitives,
private ds: DataStore,
private eventHook: EventHook,
eventHook: EventHook,
) {
// super();
this.ds.batchGet([["cache", "imageHeight"], ["cache", "widgetHeight"]])
@@ -70,23 +72,25 @@ export class Space {
this.widgetHeightCache = new LimitedMap(100, widgetCache);
}
});
eventHook.addLocalListener("file:listed", (files: FileMeta[]) => {
// console.log("Files listed", files);
this.cachedPageList = files.filter(this.isListedPage).map(
fileMetaToPageMeta,
);
});
// eventHook.addLocalListener("file:listed", (files: FileMeta[]) => {
// // console.log("Files listed", files);
// this.cachedPageList = files.filter(this.isListedPage).map(
// fileMetaToPageMeta,
// );
// });
eventHook.addLocalListener("page:deleted", (pageName: string) => {
if (this.watchedPages.has(pageName)) {
// Stop watching deleted pages already
this.watchedPages.delete(pageName);
}
});
this.updatePageListCache().catch(console.error);
}
public async updatePageList() {
public async updatePageListCache() {
console.log("Updating page list cache");
// This will trigger appropriate events automatically
await this.fetchPageList();
this.cachedPageList = await this.fetchPageList();
}
async deletePage(name: string): Promise<void> {
@@ -224,7 +228,6 @@ export class Space {
}
});
}, pageWatchInterval);
this.updatePageList().catch(console.error);
}
unwatch() {
+1 -1
View File
@@ -382,7 +382,7 @@ export class NoSyncSyncService implements ISyncService {
start() {
setInterval(() => {
// Trigger a page upload for change events
this.space.updatePageList().catch(console.error);
this.space.updatePageListCache().catch(console.error);
}, spaceSyncInterval);
}