import { useGetStickies, useClusterStickies } from '../api/api';
import type { Sticky as StickyType } from '../types/types';
import Sticky from './sticky';
import Button from './button';
import '../styles/stickies.css';
const scoreLabel = (score: number): string => {
if (score >= 0.7) return 'Strong';
if (score >= 0.4) return 'Moderate';
if (score >= 0.1) return 'Weak';
return 'Poor';
};
const Stickies = () => {
const { data: stickies, isLoading, error } = useGetStickies();
const { mutate: cluster, data: clusterResponse, isPending } = useClusterStickies();
if (isLoading) return
Loading...
;
if (error) return Error: {error.message}
;
const clusters = clusterResponse?.clusters;
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) => );
return (
{clusters ? (
{score != null && (
Cluster cohesion: {score.toFixed(2)} — {scoreLabel(score)}
)}
{clusters.map((group) => (
{group.label}
{renderStickies(
group?.noteIds
.map((id) => stickyMap?.get(id))
.filter((s): s is StickyType => !!s)
)}
))}
) : (
{renderStickies(stickies ?? [])}
)}
);
};
export default Stickies;