'use client' import { useState, useEffect } from 'react' interface BridgeNote { noteId: string bridgeScore: number clustersConnected: number[] clusterNames?: string[] note?: { id: string title: string | null content: string } } interface BridgeSuggestion { clusterAId: number clusterBId: number clusterAName: string clusterBName: string suggestedTitle: string suggestedContent: string justification: string } interface BridgeNotesDashboardProps { onNoteClick?: (noteId: string) => void } export function BridgeNotesDashboard({ onNoteClick }: BridgeNotesDashboardProps) { const [bridgeNotes, setBridgeNotes] = useState([]) const [suggestions, setSuggestions] = useState([]) const [loading, setLoading] = useState(true) const [activeTab, setActiveTab] = useState<'bridges' | 'suggestions'>('bridges') useEffect(() => { loadData() }, []) const loadData = async () => { setLoading(true) try { // Load bridge notes const bridgesRes = await fetch('/api/bridge-notes?details=true') if (bridgesRes.ok) { const bridgesData = await bridgesRes.json() setBridgeNotes(bridgesData.bridgeNotes || []) } // Load suggestions const suggestionsRes = await fetch('/api/bridge-notes/suggestions') if (suggestionsRes.ok) { const suggestionsData = await suggestionsRes.json() setSuggestions(suggestionsData.suggestions || []) } } catch (error) { console.error('Error loading bridge data:', error) } finally { setLoading(false) } } const generateNewSuggestions = async () => { try { const res = await fetch('/api/bridge-notes/suggestions', { method: 'POST' }) if (res.ok) { const data = await res.json() setSuggestions(data.suggestions || []) } } catch (error) { console.error('Error generating suggestions:', error) } } const dismissSuggestion = async (clusterAId: number, clusterBId: number) => { try { await fetch('/api/bridge-notes', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clusterAId, clusterBId }) }) // Remove from local state setSuggestions(prev => prev.filter( s => !(s.clusterAId === clusterAId && s.clusterBId === clusterBId) )) } catch (error) { console.error('Error dismissing suggestion:', error) } } if (loading) { return (
) } return (
{/* Tabs */}
{activeTab === 'bridges' && (
{bridgeNotes.length === 0 ? (

No bridge notes found yet

Bridge notes connect different clusters of ideas

) : (
{bridgeNotes.map((bridge) => (
onNoteClick?.(bridge.noteId)} className="border rounded-lg p-4 hover:shadow-md transition-shadow cursor-pointer" >
Bridge Score: {bridge.bridgeScore.toFixed(2)} Connects {bridge.clustersConnected.length} {bridge.clustersConnected.length === 1 ? 'cluster' : 'clusters'}

{bridge.note?.title || 'Untitled'}

{bridge.note?.content?.replace(/<[^>]+>/g, '').slice(0, 150) || 'No content'}

{bridge.clusterNames && bridge.clusterNames.length > 0 && (
{bridge.clusterNames.map((name, i) => ( {name} ))}
)}
))}
)}
)} {activeTab === 'suggestions' && (

AI-suggested ideas to connect your isolated clusters

{suggestions.length === 0 ? (

No connection suggestions yet

All your clusters may already be connected!

) : (
{suggestions.map((suggestion, index) => (
💡 {suggestion.suggestedTitle} #{index + 1}
{suggestion.clusterAName} ↔ {suggestion.clusterBName}

{suggestion.suggestedContent}

"{suggestion.justification}"

))}
)}
)}
) }