add actionLock to element power action

This commit is contained in:
Arthur Lu 2022-12-18 16:53:07 -08:00
parent e6290cc058
commit bb10726eef

View File

@ -24,6 +24,7 @@ class Instance extends HTMLElement {
shadowRoot.append(instanceLink);
this.shadowElement = shadowRoot;
this.actionLock = false;
}
set data (data) {
@ -63,6 +64,11 @@ class Instance extends HTMLElement {
powerButton.src = data.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg";
powerButton.alt = data.status === "running" ? "shutdown instance" : "start instance";
powerButton.addEventListener("click", async () => {
if (this.actionLock) {
console.log("already doing an action");
}
else {
this.actionLock = true;
let targetAction = this.status === "running" ? "shutdown" : "start";
let targetStatus = this.status === "running" ? "stopped" : "running";
@ -84,6 +90,8 @@ class Instance extends HTMLElement {
let powerButton = this.shadowElement.querySelector("#power-btn");
powerButton.src = this.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg";
powerButton.alt = this.status === "running" ? "shutdown instance" : "start instance";
this.actionLock = false;
}
});
let configButton = this.shadowElement.querySelector("#configure-btn");