Disable buttons that won't do anyhing

This commit is contained in:
Jeffrey Biles
2020-03-18 01:19:52 -07:00
parent e448b4b7cc
commit 2c13f9e8e8

View File

@@ -1,12 +1,12 @@
<template> <template>
<div class="bulk-action-bar"> <div class="bulk-action-bar">
<span v-if="!allSelected && emailSelection.emails.size > 0">-</span> <!-- later on this minus sign will be in the checkbox, as it is in gmail --> <span v-if="!allAreSelected && numberSelected > 0">-</span> <!-- later on this minus sign will be in the checkbox, as it is in gmail -->
<input type="checkbox" :checked="allSelected" @click="bulkSelect"> <input type="checkbox" :checked="allAreSelected" @click="bulkSelect">
<button @click="emailSelection.markRead()"> <button @click="emailSelection.markRead()" :disabled="Array.from(emailSelection.emails).every(e => e.read)">
Mark Read Mark Read
</button> </button>
<button @click="emailSelection.markUnread()"> <button @click="emailSelection.markUnread()" :disabled="Array.from(emailSelection.emails).every(e => !e.read)">
Mark Unread Mark Unread
</button> </button>
</div> </div>
@@ -19,17 +19,21 @@
export default { export default {
setup({emails}){ setup({emails}){
let {emailSelection} = useEmailSelection(); let {emailSelection} = useEmailSelection();
let allSelected = computed(() => { let numberSelected = computed(() => {
return emails.length == emailSelection.emails.size; return emailSelection.emails.size;
})
let allAreSelected = computed(() => {
return emails.length == numberSelected;
}) })
let bulkSelect = function(){ let bulkSelect = function(){
if(allSelected.value) { if(allAreSelected.value) {
emailSelection.clear(); emailSelection.clear();
} else { } else {
emailSelection.addMultiple(emails) emailSelection.addMultiple(emails)
} }
} }
return { emailSelection, allSelected, bulkSelect } return { emailSelection, allAreSelected, bulkSelect, numberSelected }
}, },
props: { props: {
emails: { emails: {