Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/i15-1/src/components/RunPlanButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Button } from "@mui/material";
import { useState } from "react";

import { useSetActiveTask, useSubmitTask } from "@atlas/blueapi-query";
import {
useGetWorkerState,
useSetActiveTask,
useSubmitTask,
} from "@atlas/blueapi-query";
import type { TaskRequest } from "@atlas/blueapi";

type RunPlanButtonProps = {
Expand Down Expand Up @@ -38,12 +42,19 @@ const RunPlanButton = ({
setLoading(false);
};

const isButtonDisabled = () => {
const workerState = useGetWorkerState();
const disable = workerState.data !== "IDLE";
return disable;
};

return (
<Button
variant="contained"
loading={loading}
sx={{ width: "150px" }}
onClick={handleClick}
disabled={isButtonDisabled()}
>
{buttonText}
</Button>
Expand Down
10 changes: 10 additions & 0 deletions apps/i15-1/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { http, HttpResponse, graphql } from "msw";

const fakeTaskId = "7304e8e0-81c6-4978-9a9d-9046ab79ce3c";
let workerStatus = { status: "IDLE", duration: 0 };

export const handlers = [
http.put("/api/worker/task", () => {
workerStatus.status = "RUNNING";
return HttpResponse.json({
task_id: fakeTaskId,
});
Expand All @@ -18,4 +20,12 @@ export const handlers = [
http.put("/api/worker/state", () => {
return HttpResponse.json("IDLE");
}),

http.get("/api/worker/state", () => {
if (workerStatus.duration >= 10) {
workerStatus.status = "IDLE";
workerStatus.duration = 0;
} else workerStatus.duration++;
return HttpResponse.json(workerStatus.status);
}),
];
Loading