The Comment button is now disabled when there is no text and the AsyncButton can now be disabled without setting it to inProgress

This commit is contained in:
bton 2024-11-27 22:01:31 +01:00
parent 8234fd438a
commit e49c62ce93
3 changed files with 14 additions and 10 deletions

View file

@ -1,9 +1,9 @@
<template> <template>
<button @click.stop="handleClick" :disabled="disabled"> <button @click.stop="handleClick" :disabled="disabled || inProgress">
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"
:class="{'d-none': !disabled}"></span> :class="{'d-none': !inProgress}"></span>
<span class="ml-2" :class="{'d-none': !disabled}">In Progress...</span> <span class="ml-2" :class="{'d-none': !inProgress}">In Progress...</span>
<span :class="{'d-none': disabled}"><slot></slot></span> <span :class="{'d-none': inProgress}"><slot></slot></span>
</button> </button>
</template> </template>
@ -13,7 +13,7 @@ export default {
name: 'AsyncButton', name: 'AsyncButton',
data() { data() {
return { return {
disabled: false, inProgress: false,
}; };
}, },
props: { props: {
@ -21,17 +21,21 @@ export default {
type: Function, type: Function,
required: true, required: true,
}, },
disabled: {
type: Boolean,
required: false,
},
}, },
methods: { methods: {
async handleClick() { async handleClick() {
if (this.task && typeof this.task === 'function') { if (this.task && typeof this.task === 'function') {
this.disabled = true; this.inProgress = true;
try { try {
await this.task(); await this.task();
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} finally { } finally {
this.disabled = false; this.inProgress = false;
} }
} }
}, },

View file

@ -17,7 +17,7 @@
<textarea placeholder="add comment..." v-model="newComment" <textarea placeholder="add comment..." v-model="newComment"
class="form-control"> class="form-control">
</textarea> </textarea>
<AsyncButton class="btn btn-primary float-right" :task="addCommentAndClear"> <AsyncButton class="btn btn-primary float-right" :task="addCommentAndClear" :disabled="!newComment">
<font-awesome-icon icon="comment"/> <font-awesome-icon icon="comment"/>
Save Comment Save Comment
</AsyncButton> </AsyncButton>