Skip to content

Commit

Permalink
fix: relation section init bug
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Aug 4, 2024
1 parent 1811a32 commit edaad57
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/modules/workspace/relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ export function registerNoteRelation() {
},
],
onInit({ body, refresh }) {
body
.querySelector("iframe")!
.contentWindow?.addEventListener("message", (ev) => {
if (ev.data.type === "openNote") {
addon.hooks.onOpenNote(
ev.data.id,
ev.data.isShift ? "window" : "tab",
);
}
});

const notifierKey = Zotero.Notifier.registerObserver(
{
notify: (event, type, ids, extraData) => {
Expand Down Expand Up @@ -81,10 +70,20 @@ export function registerNoteRelation() {
onAsyncRender: async ({ body, item }) => {
if (!item?.isNote()) return;
if (!body.querySelector("#bn-relation-graph")) {
const iframe = body.ownerDocument.createXULElement("iframe") as HTMLIFrameElement;
const iframe = body.ownerDocument.createXULElement(
"iframe",
) as HTMLIFrameElement;
iframe.src = `chrome://${config.addonRef}/content/relationGraph.html`;
iframe.id = "bn-relation-graph";
body.appendChild(iframe);
iframe.contentWindow?.addEventListener("message", (ev) => {
if (ev.data.type === "openNote") {
addon.hooks.onOpenNote(
ev.data.id,
ev.data.isShift ? "window" : "tab",
);
}
});
}
await renderGraph(body, item);
},
Expand Down

0 comments on commit edaad57

Please sign in to comment.