selection correction, api backoff time

This commit is contained in:
Kaushik Narayan R 2025-03-14 20:44:31 -07:00
parent 3a2c23e2e3
commit fae3c9bbf1
2 changed files with 55 additions and 55 deletions

View File

@ -47,7 +47,7 @@ const APIWrapper = async <B, T extends apiRespBaseType>({
} else { } else {
showErrorToastNotification(apiResp.data.message); showErrorToastNotification(apiResp.data.message);
} }
await sleep(i * i * 1000); await sleep(i * 1000);
} }
return apiResp ?? null; return apiResp ?? null;
}; };

View File

@ -106,39 +106,36 @@ const nodeProps: Partial<Node> = {
const selectedNodeProps: Partial<Node> = { const selectedNodeProps: Partial<Node> = {
style: { style: {
backgroundColor: "white", backgroundColor: "white",
boxShadow: "0px 0px 60px 20px red", boxShadow: "0px 0px 40px 10px red",
}, },
}; };
const edgeOptions: DefaultEdgeOptions = { interface buildEdgeOptionsArgs {
animated: false, animated?: boolean;
color: string;
}
const buildEdgeOptions: (opts: buildEdgeOptionsArgs) => DefaultEdgeOptions = ({
animated = false,
color,
}): DefaultEdgeOptions => {
return {
animated,
style: { style: {
stroke: "white", stroke: `${color}`,
strokeWidth: 2, strokeWidth: 2,
}, },
markerEnd: { markerEnd: {
type: MarkerType.ArrowClosed, type: MarkerType.ArrowClosed,
color: "white", color,
width: 16, width: 16,
height: 16, height: 16,
orient: "auto", orient: "auto",
}, },
};
}; };
const selectedEdgeOptions: DefaultEdgeOptions = { const edgeOptions = buildEdgeOptions({ color: "white" });
animated: true, const selectedEdgeOptions = buildEdgeOptions({ animated: true, color: "red" });
style: {
stroke: "red",
strokeWidth: 2,
},
markerEnd: {
type: MarkerType.ArrowClosed,
color: "red",
width: 16,
height: 16,
orient: "auto",
},
};
const proOptions: ProOptions = { hideAttribution: true }; const proOptions: ProOptions = { hideAttribution: true };
@ -153,6 +150,28 @@ const Graph = (): React.ReactNode => {
useState<Interactive>(initialInteractive); useState<Interactive>(initialInteractive);
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const disableInteractive = () => {
setInteractive({
ndDrag: false,
ndConn: false,
elsSel: false,
});
};
const enableInteractive = () => {
setInteractive({
ndDrag: true,
ndConn: true,
elsSel: true,
});
};
const isInteractive = useCallback(() => {
return interactive.ndDrag || interactive.ndConn || interactive.elsSel;
}, [interactive]);
const toggleInteractive = () => {
isInteractive() ? disableInteractive() : enableInteractive();
};
const onFlowInit: OnInit = (_instance) => { const onFlowInit: OnInit = (_instance) => {
console.debug("flow loaded"); console.debug("flow loaded");
}; };
@ -169,6 +188,7 @@ const Graph = (): React.ReactNode => {
const onFlowSelectionChange: OnSelectionChangeFunc = useCallback( const onFlowSelectionChange: OnSelectionChangeFunc = useCallback(
({ nodes, edges }) => { ({ nodes, edges }) => {
if (!isInteractive()) return;
const nodeSelection = nodes[0]?.id ?? ""; const nodeSelection = nodes[0]?.id ?? "";
setSelectedNodeID(nodeSelection); setSelectedNodeID(nodeSelection);
setPlaylistNodes((nds) => setPlaylistNodes((nds) =>
@ -188,7 +208,7 @@ const Graph = (): React.ReactNode => {
) )
); );
}, },
[] [isInteractive]
); );
useOnSelectionChange({ useOnSelectionChange({
onChange: onFlowSelectionChange, onChange: onFlowSelectionChange,
@ -201,7 +221,6 @@ const Graph = (): React.ReactNode => {
`new connection: ${connection.source} -> ${connection.target}` `new connection: ${connection.source} -> ${connection.target}`
); );
// call API to create link // call API to create link
const spotifyPlaylistLinkPrefix = "https://open.spotify.com/playlist/";
setLoading(true); setLoading(true);
const resp = await APIWrapper({ const resp = await APIWrapper({
apiFn: apiCreateLink, apiFn: apiCreateLink,
@ -258,7 +277,7 @@ const Graph = (): React.ReactNode => {
return; return;
} }
const selectedEdge = linkEdges.filter((ed) => ed.id === selectedEdgeID)[0]; const selectedEdge = linkEdges.filter((ed) => ed.id === selectedEdgeID)[0];
if (!selectedEdge) throw new ReferenceError("no link selected"); if (!selectedEdge) throw new ReferenceError("no edge selected");
setLoading(true); setLoading(true);
const resp = await APIWrapper({ const resp = await APIWrapper({
apiFn: apiBackfillLink, apiFn: apiBackfillLink,
@ -309,7 +328,7 @@ const Graph = (): React.ReactNode => {
const pruneLink = async () => { const pruneLink = async () => {
if (selectedEdgeID === "") { if (selectedEdgeID === "") {
showWarnToastNotification("Select an edge!"); showWarnToastNotification("Select a link!");
return; return;
} }
const selectedEdge = linkEdges.filter((ed) => ed.id === selectedEdgeID)[0]; const selectedEdge = linkEdges.filter((ed) => ed.id === selectedEdgeID)[0];
@ -496,28 +515,9 @@ const Graph = (): React.ReactNode => {
fetchGraph(); fetchGraph();
}, [fetchGraph]); }, [fetchGraph]);
const disableInteractive = () => { useEffect(() => {
setInteractive({ loading ? disableInteractive() : enableInteractive();
ndDrag: false, }, [loading]);
ndConn: false,
elsSel: false,
});
};
const enableInteractive = () => {
setInteractive({
ndDrag: true,
ndConn: true,
elsSel: true,
});
};
const isInteractive = () => {
return interactive.ndDrag || interactive.ndConn || interactive.elsSel;
};
const toggleInteractive = () => {
isInteractive() ? disableInteractive() : enableInteractive();
};
return ( return (
<div className={`${styles.graph_wrapper} ${loading && styles.loading}`}> <div className={`${styles.graph_wrapper} ${loading && styles.loading}`}>