diff --git a/lib/folk-comment-pin.ts b/lib/folk-comment-pin.ts index a56bcff..a172d60 100644 --- a/lib/folk-comment-pin.ts +++ b/lib/folk-comment-pin.ts @@ -17,6 +17,13 @@ interface SpaceMember { username: string; } +interface RNoteItem { + id: string; + title: string; + type: string; + updated_at: string; +} + export class CommentPinManager { #container: HTMLElement; #canvasContent: HTMLElement; @@ -32,6 +39,7 @@ export class CommentPinManager { #openPinId: string | null = null; #members: SpaceMember[] | null = null; #mentionDropdown: HTMLElement | null = null; + #notes: RNoteItem[] | null = null; constructor( container: HTMLElement, @@ -255,6 +263,30 @@ export class CommentPinManager { this.#renderAllPins(); } + linkNote(pinId: string, noteId: string, noteTitle: string) { + const newDoc = Automerge.change(this.#sync.doc, "Link note to pin", (doc) => { + if (doc.commentPins?.[pinId]) { + doc.commentPins[pinId].linkedNoteId = noteId; + doc.commentPins[pinId].linkedNoteTitle = noteTitle; + } + }); + this.#sync._applyDocChange(newDoc); + if (this.#openPinId === pinId) this.#openPinPopover(pinId, false); + this.#renderAllPins(); + } + + unlinkNote(pinId: string) { + const newDoc = Automerge.change(this.#sync.doc, "Unlink note from pin", (doc) => { + if (doc.commentPins?.[pinId]) { + delete (doc.commentPins[pinId] as any).linkedNoteId; + delete (doc.commentPins[pinId] as any).linkedNoteTitle; + } + }); + this.#sync._applyDocChange(newDoc); + if (this.#openPinId === pinId) this.#openPinPopover(pinId, false); + this.#renderAllPins(); + } + toggleShowResolved() { this.#showResolved = !this.#showResolved; this.#renderAllPins(); @@ -468,7 +500,20 @@ export class CommentPinManager { (!this.#sync.doc.shapes?.[pin.anchor.shapeId] || (this.#sync.doc.shapes[pin.anchor.shapeId] as any).deleted); - let html = ` + let html = ``; + + // Header + html += `