|
| 1 | +import React, { useEffect, useRef } from 'react'; |
| 2 | +import * as d3 from 'd3'; |
| 3 | +import { useTheme } from 'next-themes'; |
| 4 | + |
| 5 | +interface Message { |
| 6 | + content: string | { |
| 7 | + type: string; |
| 8 | + tree?: Array<{ |
| 9 | + id: number; |
| 10 | + parent_id: number | null; |
| 11 | + action: string; |
| 12 | + description: string | null; |
| 13 | + }>; |
| 14 | + }; |
| 15 | + type: 'incoming' | 'outgoing'; |
| 16 | + timestamp: string; |
| 17 | +} |
| 18 | + |
| 19 | +interface SimpleSearchVisualProps { |
| 20 | + messages: Message[]; |
| 21 | +} |
| 22 | + |
| 23 | +const SimpleSearchVisual: React.FC<SimpleSearchVisualProps> = ({ messages }) => { |
| 24 | + const svgRef = useRef<SVGSVGElement>(null); |
| 25 | + const containerRef = useRef<HTMLDivElement>(null); |
| 26 | + const { theme } = useTheme(); |
| 27 | + |
| 28 | + // Simple placeholder visualization |
| 29 | + useEffect(() => { |
| 30 | + if (!svgRef.current || !messages.length) return; |
| 31 | + |
| 32 | + // Clear previous content |
| 33 | + const svg = d3.select(svgRef.current); |
| 34 | + svg.selectAll("*").remove(); |
| 35 | + |
| 36 | + // Create a simple placeholder visualization |
| 37 | + const width = 400; |
| 38 | + const height = 700; |
| 39 | + const margin = { top: 20, right: 20, bottom: 20, left: 20 }; |
| 40 | + |
| 41 | + // Filter tree_update messages |
| 42 | + const treeUpdates = messages.filter(msg => { |
| 43 | + try { |
| 44 | + const data = typeof msg.content === 'string' ? JSON.parse(msg.content) : msg.content; |
| 45 | + return data.type === 'tree_update'; |
| 46 | + } catch { |
| 47 | + return false; |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + // Draw placeholder circles for each tree update |
| 52 | + const g = svg.append("g") |
| 53 | + .attr("transform", `translate(${margin.left},${margin.top})`); |
| 54 | + |
| 55 | + g.selectAll("circle") |
| 56 | + .data(treeUpdates) |
| 57 | + .enter() |
| 58 | + .append("circle") |
| 59 | + .attr("cx", (d, i) => (i % 3) * 100 + 50) |
| 60 | + .attr("cy", (d, i) => Math.floor(i / 3) * 100 + 50) |
| 61 | + .attr("r", 20) |
| 62 | + .attr("fill", theme === 'dark' ? "#4B5563" : "#9CA3AF") |
| 63 | + .attr("stroke", theme === 'dark' ? "#374151" : "#E5E7EB"); |
| 64 | + |
| 65 | + // Add placeholder text |
| 66 | + g.append("text") |
| 67 | + .attr("x", width / 2) |
| 68 | + .attr("y", height / 2) |
| 69 | + .attr("text-anchor", "middle") |
| 70 | + .attr("fill", theme === 'dark' ? "#FFFFFF" : "#111827") |
| 71 | + .text(`Tree Updates: ${treeUpdates.length}`); |
| 72 | + |
| 73 | + }, [messages, theme]); |
| 74 | + |
| 75 | + return ( |
| 76 | + <div className="w-[30%] bg-white dark:bg-slate-800 rounded-r-lg overflow-hidden"> |
| 77 | + <div className="p-3 border-b border-slate-200 dark:border-slate-700 bg-gradient-to-r from-sky-50 to-white dark:from-slate-900 dark:to-slate-800"> |
| 78 | + <h2 className="text-lg font-semibold text-sky-950 dark:text-sky-100 flex items-center"> |
| 79 | + <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5 mr-2 text-cyan-500" viewBox="0 0 20 20" fill="currentColor"> |
| 80 | + <path d="M7 3a1 1 0 000 2h6a1 1 0 100-2H7zM4 7a1 1 0 011-1h10a1 1 0 110 2H5a1 1 0 01-1-1zM2 11a2 2 0 012-2h12a2 2 0 012 2v4a2 2 0 01-2 2H4a2 2 0 01-2-2v-4z" /> |
| 81 | + </svg> |
| 82 | + Tree Visualization |
| 83 | + </h2> |
| 84 | + </div> |
| 85 | + <div ref={containerRef} className="h-[calc(100%-48px)] w-full overflow-auto bg-gradient-to-r from-sky-50 to-white dark:from-slate-900 dark:to-slate-800"> |
| 86 | + <svg |
| 87 | + ref={svgRef} |
| 88 | + width="400" |
| 89 | + height="700" |
| 90 | + className="overflow-visible" |
| 91 | + ></svg> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + ); |
| 95 | +}; |
| 96 | + |
| 97 | +export default SimpleSearchVisual; |
0 commit comments