import { useState, useEffect, useRef } from 'react'; import type { DragEvent } from 'react'; import { useGetStickies, useClusterStickies } from '../api/api'; import type { Sticky as StickyType, RankedCluster } from '../types/types'; import Sticky from './sticky'; import Button from './button'; import '../styles/stickies.css'; // In practice, silhouette on cosine distance between text embeddings occupies roughly // [-0.05, 0.10], not strict theoretical [-1, 1]: near-orthogonal vectors put both the within- and // nearest-cluster distances close to 0.8, and the coefficient divides their gap // by the larger. These bands are calibrated to that range for voyage-3. see README, Reading the cohesion score const scoreLabel = (score: number): string => { if (score >= 0.07) return 'Strong'; if (score >= 0.04) return 'Moderate'; if (score >= 0.01) return 'Weak'; return 'Poor'; }; const Stickies = () => { const { data: stickies, isLoading, error } = useGetStickies(); const { mutate: cluster, data: clusterResponse, isPending } = useClusterStickies(); const [rankedClusters, setRankedClusters] = useState([]); const dragIndex = useRef(null); const [dragOverIndex, setDragOverIndex] = useState(null); useEffect(() => { if (clusterResponse?.clusters) { setRankedClusters( clusterResponse.clusters.map((c, i) => ({ ...c, rank: i + 1 })) ); } }, [clusterResponse]); if (isLoading) return
Loading...
; if (error) return
Error: {error.message}
; const score = clusterResponse?.score; const handleCluster = () => { cluster(); }; const buildStickyMap = (): Map => { const map = new Map(); stickies?.forEach((s) => map.set(s.id, s)); return map; }; const stickyMap = buildStickyMap(); const renderStickies = (items: StickyType[]) => items?.map((sticky) => ); const handleDragStart = (index: number) => { dragIndex.current = index; }; const handleDragOver = (e: DragEvent, index: number) => { e.preventDefault(); setDragOverIndex(index); }; const handleDragLeave = () => { setDragOverIndex(null); }; const handleDrop = (targetIndex: number) => { const sourceIndex = dragIndex.current; if (sourceIndex === null || sourceIndex === targetIndex) { dragIndex.current = null; setDragOverIndex(null); return; } const reordered = [...rankedClusters]; const [moved] = reordered.splice(sourceIndex, 1); reordered.splice(targetIndex, 0, moved); setRankedClusters(reordered.map((c, i) => ({ ...c, rank: i + 1 }))); dragIndex.current = null; setDragOverIndex(null); }; const handleDragEnd = () => { dragIndex.current = null; setDragOverIndex(null); }; console.log(score?.toFixed(2)) return (
); }; export default Stickies;