import { useEffect, useState } from "react"; import { apiAuth, baseUrl, token } from "./api"; import useAuthContext from "./AuthContext"; //const debounce = void>( // func: T, // delay: number //): ((...args: Parameters) => void) => { // let timeoutId: number | null = null; // return (...args: Parameters) => { // if (timeoutId !== null) { // clearTimeout(timeoutId); // } // console.log(timeoutId); // timeoutId = setTimeout(() => { // func(...args); // }, delay); // }; //}; // interface Prop { name: string; min: string; max: string; step: string; value: string; } interface Params { nodeSize: number; edgeWidth: number; arrowSize: number; fontSize: number; distance: number; weighting: boolean; popularity: boolean; show: number; } interface DeferredProps { timeout: number; func: () => void; } let timeoutID: number | null = null; export default function Analysis() { const [image, setImage] = useState(""); const [params, setParams] = useState({ nodeSize: 2000, edgeWidth: 1, arrowSize: 16, fontSize: 10, distance: 2, weighting: true, popularity: true, show: 2, }); const [showControlPanel, setShowControlPanel] = useState(false); const [loading, setLoading] = useState(true); // Function to generate and fetch the graph image async function loadImage() { setLoading(true); await apiAuth("analysis/image", params, "POST") .then((data) => { setImage(data.image); setLoading(false); }).catch((e) => { const { checkAuth } = useAuthContext(); checkAuth(); }) } useEffect(() => { if (timeoutID) { clearTimeout(timeoutID); } timeoutID = setTimeout(() => { loadImage(); }, 1000); }, [params]); function showLabel() { switch (params.show) { case 0: return "dislike"; case 1: return "both"; case 2: return "like"; } } const { user } = useAuthContext()! console.log(`logged in as ${user.username}`); return (
setParams({ ...params, show: Number(evt.target.value) })} />
{showLabel()}
setParams({ ...params, weighting: evt.target.checked })} />
setParams({ ...params, popularity: evt.target.checked })} />
setParams({ ...params, distance: Number(evt.target.value) })} /> {params.distance}
setParams({ ...params, nodeSize: Number(evt.target.value) })} /> {params.nodeSize}
setParams({ ...params, fontSize: Number(evt.target.value) })} /> {params.fontSize}
setParams({ ...params, edgeWidth: Number(evt.target.value) })} /> {params.edgeWidth}
setParams({ ...params, arrowSize: Number(evt.target.value) })} /> {params.arrowSize}
{ loading ? ( ) : ( ) }
); }