Skip to content

Commit

Permalink
Fixed wrong reset button state in node configuration when open
Browse files Browse the repository at this point in the history
  • Loading branch information
andev0 committed Sep 6, 2024
1 parent e88333b commit dcbaa98
Showing 1 changed file with 46 additions and 30 deletions.
76 changes: 46 additions & 30 deletions src/Sankey/NodeConfiguration/NodeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,17 @@ export class NodeConfiguration extends EventTarget

this.setupTableElements(recipe, machine);

let updateResetButton = () =>
this.addEventListener(NodeConfiguration.machinesAmountChangedEvent, () =>
{
if (this._isOpened)
{
if (this.machinesAmount !== this._openingMachinesAmount
|| this.overclockRatio !== this._openingOverclockRatio)
{
NodeConfiguration._restoreButton.classList.remove("disabled");
}
else
{
NodeConfiguration._restoreButton.classList.add("disabled");
}

if (this.machinesAmount !== 1 || this.overclockRatio !== 1)
{
NodeConfiguration._resetButton.classList.remove("disabled");
}
else
{
NodeConfiguration._resetButton.classList.add("disabled");
}
}
};
this.updateResetButton();
this.updateRestoreButton();
});

this.addEventListener(NodeConfiguration.machinesAmountChangedEvent, updateResetButton);
this.addEventListener(NodeConfiguration.overclockChangedEvent, updateResetButton);
this.addEventListener(NodeConfiguration.overclockChangedEvent, () =>
{
this.updateResetButton();
this.updateRestoreButton();
});

NodeConfiguration._restoreButton.addEventListener("click", () =>
{
Expand Down Expand Up @@ -120,7 +104,7 @@ export class NodeConfiguration extends EventTarget
this.machinesAmount = this._openingMachinesAmount;
this.overclockRatio = this._openingOverclockRatio;

// Machines amount group
/* Machines amount group */

NodeConfiguration._machinesColumn.appendChild(this._machineConfigurator!);

Expand All @@ -137,7 +121,7 @@ export class NodeConfiguration extends EventTarget
this._amountConfigurators.powerConfigurator!
);

// Overclock group
/* Overclock group */

NodeConfiguration._multipliersColumn.appendChild(this._overclockConfigurator!);

Expand All @@ -154,13 +138,14 @@ export class NodeConfiguration extends EventTarget
this._overclockConfigurators.powerConfigurator!
);

// Modal window

NodeConfiguration._restoreButton.classList.add("disabled");
/* Modal window */

NodeConfiguration._modalContainer.classList.remove("hidden");

this._isOpened = true;

this.updateResetButton();
this.updateRestoreButton();
}

private closeConfigurationWindow(): void
Expand Down Expand Up @@ -313,6 +298,37 @@ export class NodeConfiguration extends EventTarget
.build();
}

private updateRestoreButton()
{
if (this._isOpened)
{
if (this.machinesAmount !== this._openingMachinesAmount
|| this.overclockRatio !== this._openingOverclockRatio)
{
NodeConfiguration._restoreButton.classList.remove("disabled");
}
else
{
NodeConfiguration._restoreButton.classList.add("disabled");
}
}
}

private updateResetButton()
{
if (this._isOpened)
{
if (this.machinesAmount !== 1 || this.overclockRatio !== 1)
{
NodeConfiguration._resetButton.classList.remove("disabled");
}
else
{
NodeConfiguration._resetButton.classList.add("disabled");
}
}
}

public get machinesAmount(): number
{
return this._machinesAmount;
Expand Down

0 comments on commit dcbaa98

Please sign in to comment.