Skip to content

Commit

Permalink
chore: cleanup cancel func
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Dec 17, 2024
1 parent ddf5761 commit 86624e8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions ui/src/components/Graph/modules/Controls.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, memo } from "react";
import { FC, memo, useCallback } from "react";

import { defaultAggregatedData, useGraphContext } from "@/contexts/GraphContext/context";
import { useHandlers } from "../hooks/useHandlers";
Expand All @@ -9,6 +9,19 @@ export const Controls: FC = memo(() => {
const { handleResetSim } = useHandlers();
const { startStream, streaming, stopStream } = useStreamMessagesHandler();

const handleCancelSim = useCallback(() => {
() => {
stopStream();
dispatch({
type: "BATCH_UPDATE",
payload: {
currentNode: undefined,
aggregatedData: defaultAggregatedData,
},
});
}
}, [stopStream, dispatch])

return (
<div className="min-w-[200px] flex items-center justify-end gap-4">
<button
Expand All @@ -20,16 +33,7 @@ export const Controls: FC = memo(() => {
</button>
<button
className="bg-gray-400 text-white w-[80px] rounded-md px-4 py-2"
onClick={streaming ? () => {
stopStream();
dispatch({
type: "BATCH_UPDATE",
payload: {
currentNode: undefined,
aggregatedData: defaultAggregatedData,
},
});
} : handleResetSim}
onClick={streaming ? handleCancelSim : handleResetSim}
>
{streaming ? "Cancel" : "Reset"}
</button>
Expand Down

0 comments on commit 86624e8

Please sign in to comment.