Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: update publish view popup when monographs sync (#10007)

01zulfi146216949dc4
diff --git a/apps/web/src/components/publish-view/index.tsx b/apps/web/src/components/publish-view/index.tsx
index 611795ab1..665e25c30 100644
--- a/apps/web/src/components/publish-view/index.tsx
+++ b/apps/web/src/components/publish-view/index.tsx
@@ -82,6 +82,29 @@ function PublishView(props: PublishViewProps) {
};
}, [note.id]);
+ useEffect(() => {
+ const monographsUpdatedEvent = db.eventManager.subscribe(
+ EVENTS.monographsUpdated,
+ async (ids?: string[]) => {
+ if (ids && ids.length > 0 && !ids.includes(note.id)) return;
+
+ const m = await resolveMonograph(note.id);
+ setMonograph(m);
+
+ // if monograph has been unpublished, reset all the fields
+ if (!m) {
+ setSelfDestruct(false);
+ if (titleInput.current) titleInput.current.value = note.title;
+ if (passwordInput.current) passwordInput.current.value = "";
+ }
+ }
+ );
+
+ return () => {
+ monographsUpdatedEvent.unsubscribe();
+ };
+ }, [note.id]);
+
return (
<>
{monograph?.id ? (
diff --git a/packages/core/src/api/sync/index.ts b/packages/core/src/api/sync/index.ts
index ae470cb07..ecb8bb7f6 100644
--- a/packages/core/src/api/sync/index.ts
+++ b/packages/core/src/api/sync/index.ts
@@ -560,15 +560,18 @@ export class Sync {
return true;
});
- this.connection.on("SendMonographs", async (monographs) => {
+ this.connection.on("SendMonographs", async (monographs: Monograph[]) => {
if (this.connection?.state !== HubConnectionState.Connected) return false;
- this.db.monographsCollection.collection.put(
- monographs.map((m: Monograph) => ({
+ const ids = monographs.map((m) => m.id);
+ await this.db.monographsCollection.collection.put(
+ monographs.map((m) => ({
...m,
type: "monograph"
}))
);
+ await this.db.monographs.refresh().catch(this.logger.error);
+ this.db.eventManager.publish(EVENTS.monographsUpdated, ids);
return true;
});
diff --git a/packages/core/src/common.ts b/packages/core/src/common.ts
index 8bf9d69f2..83bd26e65 100644
--- a/packages/core/src/common.ts
+++ b/packages/core/src/common.ts
@@ -103,6 +103,7 @@ export const EVENTS = {
fileUploaded: "file:uploaded",
attachmentDeleted: "attachment:deleted",
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
+ monographsUpdated: "monographs:updated",
vaultLocked: "vault:locked",
vaultUnlocked: "vault:unlocked",
systemTimeInvalid: "system:invalidTime",