From 9d4127ba6d528345683cc836239494f666158a39 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 29 Sep 2025 19:04:00 +0300 Subject: [PATCH] chore(type_widgets): render note box --- .../type_widgets/RelationMap.css} | 0 .../src/widgets/type_widgets/RelationMap.tsx | 46 +++++++++++++++++-- .../widgets/type_widgets_old/relation_map.ts | 24 ---------- 3 files changed, 42 insertions(+), 28 deletions(-) rename apps/client/src/{stylesheets/relation_map.css => widgets/type_widgets/RelationMap.css} (100%) diff --git a/apps/client/src/stylesheets/relation_map.css b/apps/client/src/widgets/type_widgets/RelationMap.css similarity index 100% rename from apps/client/src/stylesheets/relation_map.css rename to apps/client/src/widgets/type_widgets/RelationMap.css diff --git a/apps/client/src/widgets/type_widgets/RelationMap.tsx b/apps/client/src/widgets/type_widgets/RelationMap.tsx index c77ad6461..38f0ef2bf 100644 --- a/apps/client/src/widgets/type_widgets/RelationMap.tsx +++ b/apps/client/src/widgets/type_widgets/RelationMap.tsx @@ -3,6 +3,11 @@ import { TypeWidgetProps } from "./type_widget"; import { Defaults, jsPlumb, OverlaySpec } from "jsplumb"; import { useNoteBlob } from "../react/hooks"; import FNote from "../../entities/fnote"; +import { ComponentChildren } from "preact"; +import froca from "../../services/froca"; +import NoteLink from "../react/NoteLink"; +import "./RelationMap.css"; +import { t } from "../../services/i18n"; interface MapData { notes: { @@ -32,7 +37,6 @@ const uniDirectionalOverlays: OverlaySpec[] = [ export default function RelationMap({ note }: TypeWidgetProps) { const data = useData(note); - console.log("Got data", data); return (
@@ -45,7 +49,11 @@ export default function RelationMap({ note }: TypeWidgetProps) { ConnectionOverlays: uniDirectionalOverlays, HoverPaintStyle: { stroke: "#777", strokeWidth: 1 }, }} - /> + > + {data.notes.map(note => ( + + ))} +
) @@ -81,9 +89,10 @@ function useData(note: FNote) { return content; } -function JsPlumb({ className, props }: { +function JsPlumb({ className, props, children }: { className?: string; props: Omit; + children: ComponentChildren; }) { const containerRef = useRef(null); @@ -100,7 +109,36 @@ function JsPlumb({ className, props }: { return (
- + {children}
) } + +function NoteBox({ noteId, x, y }: MapData["notes"][number]) { + const [ note, setNote ] = useState(); + useEffect(() => { + froca.getNote(noteId).then(setNote); + }, [ noteId ]); + + return note && ( +
+ +
+
+ ) +} + +function noteIdToId(noteId: string) { + return `rel-map-note-${noteId}`; +} + +function idToNoteId(id: string) { + return id.substr(13); +} diff --git a/apps/client/src/widgets/type_widgets_old/relation_map.ts b/apps/client/src/widgets/type_widgets_old/relation_map.ts index 9b37f2773..f398156dd 100644 --- a/apps/client/src/widgets/type_widgets_old/relation_map.ts +++ b/apps/client/src/widgets/type_widgets_old/relation_map.ts @@ -11,7 +11,6 @@ import dialogService from "../../services/dialog.js"; import { t } from "../../services/i18n.js"; import type FNote from "../../entities/fnote.js"; import type { ConnectionMadeEventInfo, jsPlumbInstance, OverlaySpec } from "jsplumb"; -import "../../stylesheets/relation_map.css"; declare module "jsplumb" { @@ -247,13 +246,7 @@ export default class RelationMapTypeWidget extends TypeWidget { } } - noteIdToId(noteId: string) { - return `rel-map-note-${noteId}`; - } - idToNoteId(id: string) { - return id.substr(13); - } async doRefresh(note: FNote) { await this.loadMapData(); @@ -532,23 +525,6 @@ export default class RelationMapTypeWidget extends TypeWidget { return; } - const $link = await linkService.createLink(noteId, { title }); - $link.mousedown((e) => linkService.goToLink(e)); - - const note = await froca.getNote(noteId); - if (!note) { - return; - } - - const $noteBox = $("
") - .addClass("note-box") - .addClass(note.getCssClass()) - .prop("id", this.noteIdToId(noteId)) - .append($("").addClass("title").append($link)) - .append($("
").addClass("endpoint").attr("title", t("relation_map.start_dragging_relations"))) - .css("left", `${x}px`) - .css("top", `${y}px`); - this.jsPlumbInstance.getContainer().appendChild($noteBox[0]); this.jsPlumbInstance.draggable($noteBox[0], {