chain pruning

This commit is contained in:
2025-03-15 00:21:17 -07:00
parent fae3c9bbf1
commit c1c4d4d45a
3 changed files with 49 additions and 7 deletions

View File

@@ -48,6 +48,7 @@ import {
apiCreateLink,
apiDeleteLink,
apiFetchGraph,
apiPruneChain,
apiPruneLink,
apiUpdateUserData,
} from "../../api/operations.ts";
@@ -354,6 +355,34 @@ const Graph = (): React.ReactNode => {
return;
};
const pruneChain = async () => {
if (selectedNodeID === "") {
showWarnToastNotification("Select a playlist!");
return;
}
const selectedNode = playlistNodes.filter(
(nd) => nd.id === selectedNodeID
)[0];
if (!selectedNode) throw new ReferenceError("no playlist selected");
setLoading(true);
const resp = await APIWrapper({
apiFn: apiPruneChain,
data: {
root: spotifyPlaylistLinkPrefix + selectedNodeID,
},
refreshAuth,
});
setLoading(false);
if (resp?.status === 200) {
if (resp?.data.deletedNum < resp?.data.toDelNum)
showWarnToastNotification(resp?.data.message);
else showSuccessToastNotification(resp?.data.message);
return;
}
return;
};
type getLayoutedElementsOpts = {
direction: rankdirType;
};
@@ -570,9 +599,9 @@ const Graph = (): React.ReactNode => {
<PiSubsetOf size={36} />
Prune Link
</Button>
<Button disabled={loading}>
<Button disabled={loading} onClickMethod={pruneChain}>
<PiSubsetOf size={36} />
Prune Link
Prune Chain
</Button>
<hr className={styles.divider} />
<Button disabled={loading} onClickMethod={() => arrangeLayout("TB")}>