Skip to content

Commit

Permalink
Fix restart button
Browse files Browse the repository at this point in the history
  • Loading branch information
hendriksen-mark committed Sep 2, 2024
1 parent 158bd45 commit 0010aa8
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Pages/Bridge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const Bridge = ({ HOST_IP, API_KEY }) => {
color="blue"
size=""
type="submit"
onClick={() => dumpConfig()}
onClick={() => dumpConfig(false)}
/>
</div>
<div className="form-control">
Expand All @@ -144,11 +144,14 @@ const Bridge = ({ HOST_IP, API_KEY }) => {
openWizard();
};

const dumpConfig = () => {
const dumpConfig = (restart) => {
axios
.get(`${HOST_IP}/save`)
.then(() => {
toast.success("Config dumped to local disk");
if (restart === true){
Restart();
}
})
.catch((error) => {
console.error(error);
Expand Down Expand Up @@ -184,32 +187,19 @@ const Bridge = ({ HOST_IP, API_KEY }) => {
closeWizard()
};

const Restart = () => {
const RestartAlert = () => {
confirmAlert({
title: "Restart Python.",
message:
"Are you sure to do this?\nThis will NOT save the current config.",
buttons: [
{
label: "Yes",
onClick: () =>
axios
.get(`${HOST_IP}/restart`)
.then(() => {
toast.success("Restart Python");
})
.catch((error) => {
if (error.message === "Network Error") {
toast.success("Restart Python");
} else {
console.error(error);
toast.error(`Error occurred: ${error.message}`);
}
}),
onClick: () => Restart(),
},
{
label: "Save first",
onClick: () => dumpConfig(),
onClick: () => dumpConfig(true),
},
{
label: "No",
Expand All @@ -218,6 +208,22 @@ const Bridge = ({ HOST_IP, API_KEY }) => {
});
};

const Restart = () => {
axios
.get(`${HOST_IP}/restart`)
.then(() => {
toast.success("Restart Python");
})
.catch((error) => {
if (error.message === "Network Error") {
toast.success("Restart Python");
} else {
console.error(error);
toast.error(`Error occurred: ${error.message}`);
}
})
};

const restoreOptions = () => {
setWizardName("Reset Config Options");
setWizardContent(
Expand Down Expand Up @@ -556,7 +562,7 @@ const Bridge = ({ HOST_IP, API_KEY }) => {
color="red"
size=""
type="submit"
onClick={() => Restart()}
onClick={() => RestartAlert()}
/>
</div>
<div className="form-control">
Expand Down

0 comments on commit 0010aa8

Please sign in to comment.