Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable modal buttons when in progress #1532

Merged
merged 4 commits into from
Nov 11, 2024
Merged
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
9 changes: 8 additions & 1 deletion src/components/profiles-modals/CreateProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ProfilesMixin from "../../components/mixins/ProfilesMixin.vue";
})
export default class CreateProfileModal extends ProfilesMixin {

private creatingInProgress: boolean = false;
private newProfileName = '';

get isOpen(): boolean {
Expand All @@ -17,17 +18,23 @@ export default class CreateProfileModal extends ProfilesMixin {

closeModal() {
this.newProfileName = '';
this.creatingInProgress = false;
this.$store.commit('closeCreateProfileModal');
}

// User confirmed creation of a new profile with a name that didn't exist before.
async createProfile() {
if (this.creatingInProgress) {
return;
}
const safeName = this.makeProfileNameSafe(this.newProfileName);
if (safeName !== '') {
try {
this.creatingInProgress = true;
await this.$store.dispatch('profiles/addProfile', safeName);
this.closeModal();
} catch (e) {
this.creatingInProgress = false;
const err = R2Error.fromThrownValue(e, 'Error whilst creating a profile');
this.$store.commit('error/handleError', err);
}
Expand Down Expand Up @@ -67,7 +74,7 @@ export default class CreateProfileModal extends ProfilesMixin {

<template v-slot:footer>
<button id="modal-create-profile-invalid" class="button is-danger" v-if="doesProfileExist(newProfileName)" disabled>Create</button>
<button id="modal-create-profile" class="button is-info" @click="createProfile(newProfileName)" v-else>Create</button>
<button id="modal-create-profile" class="button is-info" @click="createProfile(newProfileName)" :disabled="creatingInProgress" v-else>Create</button>
</template>

</ModalCard>
Expand Down
8 changes: 8 additions & 0 deletions src/components/profiles-modals/DeleteProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ import ProfilesMixin from "../../components/mixins/ProfilesMixin.vue";
components: {ModalCard}
})
export default class DeleteProfileModal extends ProfilesMixin {
private deletingInProgress: boolean = false;

get isOpen(): boolean {
return this.$store.state.modals.isDeleteProfileModalOpen;
}

closeDeleteProfileModal() {
this.deletingInProgress = false;
this.$store.commit('closeDeleteProfileModal');
}

async removeProfile() {
if (this.deletingInProgress) {
return;
}
try {
this.deletingInProgress = true;
await this.$store.dispatch('profiles/removeSelectedProfile');
} catch (e) {
const err = R2Error.fromThrownValue(e, 'Error whilst deleting profile');
Expand All @@ -41,6 +48,7 @@ export default class DeleteProfileModal extends ProfilesMixin {
</template>
<template v-slot:footer>
<button
:disabled="deletingInProgress"
class="button is-danger"
@click="removeProfile()"
>Delete profile</button>
Expand Down
8 changes: 7 additions & 1 deletion src/components/profiles-modals/RenameProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ProfilesMixin from "../../components/mixins/ProfilesMixin.vue";
export default class RenameProfileModal extends ProfilesMixin {
@Ref() readonly nameInput: HTMLInputElement | undefined;
private newProfileName: string = '';
private renamingInProgress: boolean = false;

@Watch('$store.state.profile.activeProfile')
activeProfileChanged(newProfile: Profile, oldProfile: Profile|null) {
Expand Down Expand Up @@ -41,12 +42,17 @@ export default class RenameProfileModal extends ProfilesMixin {
}

closeModal() {
this.renamingInProgress = false;
this.newProfileName = this.$store.state.profile.activeProfile.getProfileName();
this.$store.commit('closeRenameProfileModal');
}

async performRename() {
if (this.renamingInProgress) {
return;
}
try {
this.renamingInProgress = true;
await this.$store.dispatch('profiles/renameProfile', {newName: this.newProfileName});
} catch (e) {
const err = R2Error.fromThrownValue(e, 'Error whilst renaming profile');
Expand Down Expand Up @@ -85,7 +91,7 @@ export default class RenameProfileModal extends ProfilesMixin {
</template>
<template v-slot:footer>
<button class="button is-danger" v-if="doesProfileExist(newProfileName)" disabled>Rename</button>
<button class="button is-info" @click="performRename(newProfileName)" v-else>Rename</button>
<button class="button is-info" @click="performRename(newProfileName)" :disabled="renamingInProgress" v-else>Rename</button>
</template>

</ModalCard>
Expand Down
Loading