diff --git a/src/components/ArgumentGraph.tsx b/src/components/ArgumentGraph.tsx new file mode 100644 index 0000000..5a91719 --- /dev/null +++ b/src/components/ArgumentGraph.tsx @@ -0,0 +1,344 @@ +import { useCallback, useEffect, useMemo, useState } from "react"; +import ReactFlow, { + Background, + Controls, + Handle, + MiniMap, + Position, + applyEdgeChanges, + applyNodeChanges, + type Connection, + type Edge, + type EdgeChange, + type Node, + type NodeChange, + type NodeProps, + type XYPosition, +} from "reactflow"; +import "reactflow/dist/style.css"; +import { useEditorContext } from "../contexts/EditorContext"; +import { useSession } from "../contexts/SessionContext"; +import { LABEL_CONFIGS } from "../types/labels"; +import type { Highlight, Relationship } from "../types"; + +interface HighlightNodeData { + highlight: Highlight; + color: string; + onEditText: (id: string, newText: string) => void; + onDelete: (id: string) => void; +} + +function HighlightNode({ data }: NodeProps) { + const { highlight, color, onEditText, onDelete } = data; + const [isEditing, setIsEditing] = useState(false); + const [draft, setDraft] = useState(highlight.text); + + const commit = () => { + setIsEditing(false); + const next = draft.trim(); + if (next && next !== highlight.text) onEditText(highlight.id, next); + else setDraft(highlight.text); + }; + + return ( +
+ +
+ + {highlight.labelType} + +
+ + +
+
+ {isEditing ? ( +