Skip to content

Commit

Permalink
Disable toggle element while operation is in progress
Browse files Browse the repository at this point in the history
- Prevent mod enable/disable toggle starting another process while one
  is already in progress
- Don't disable the input element itself, since this would show a
  disabled checkbox while the process is in progress, and I don't want
  to deal with the CSS right now
- Make switch ids unique
  • Loading branch information
anttimaki committed Apr 9, 2024
1 parent e6f26e0 commit 6c7c4d1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/components/views/LocalModList/LocalModCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class LocalModCard extends Vue {
disabledDependencies: ManifestV2[] = [];
missingDependencies: string[] = [];
disableChangePending = false;
get donationLink() {
return this.tsMod ? this.tsMod.getDonationLink() : undefined;
Expand Down Expand Up @@ -69,11 +70,17 @@ export default class LocalModCard extends Vue {
}
async disableMod() {
if (this.disableChangePending) {
return;
}
this.disableChangePending = true;
const dependants = Dependants.getDependantList(this.mod, this.localModList);
for (const mod of dependants) {
if (mod.isEnabled()) {
this.$store.commit('openDisableModModal', this.mod);
this.disableChangePending = false;
return;
}
}
Expand All @@ -89,9 +96,16 @@ export default class LocalModCard extends Vue {
severity: LogSeverity.ACTION_STOPPED
});
}
this.disableChangePending = false;
}
async enableMod(mod: ManifestV2) {
if (this.disableChangePending) {
return;
}
this.disableChangePending = true;
const dependencies = Dependants.getDependencyList(mod, this.localModList);
try {
Expand All @@ -105,6 +119,8 @@ export default class LocalModCard extends Vue {
severity: LogSeverity.ACTION_STOPPED
});
}
this.disableChangePending = false;
}
async uninstallMod() {
Expand Down Expand Up @@ -220,12 +236,12 @@ function dependencyStringToModName(x: string) {
<span @click.prevent.stop="() => mod.isEnabled() ? disableMod() : enableMod(mod)"
class='card-header-icon'>
<div class="field">
<input id="switchExample"
<input :id="`switch-${mod.getName()}`"
type="checkbox"
name="switchExample"
:class='`switch is-small ${mod.isEnabled() ? "switch is-info" : ""}`'
:checked="mod.isEnabled()" />
<label for="switchExample" v-tooltip.left="mod.isEnabled() ? 'Disable' : 'Enable'"></label>
<label :for="`switch-${mod.getName()}`"
v-tooltip.left="mod.isEnabled() ? 'Disable' : 'Enable'"></label>
</div>
</span>
</template>
Expand Down

0 comments on commit 6c7c4d1

Please sign in to comment.