mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-24 07:55:34 +00:00
Bulk Select checkbox
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
<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 -->
|
||||||
|
<input type="checkbox" :checked="allSelected" @click="bulkSelect">
|
||||||
|
|
||||||
<button @click="emailSelection.markRead()">
|
<button @click="emailSelection.markRead()">
|
||||||
Mark Read
|
Mark Read
|
||||||
</button>
|
</button>
|
||||||
@@ -11,13 +14,29 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import useEmailSelection from '../composition/useEmailSelection';
|
import useEmailSelection from '../composition/useEmailSelection';
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup(){
|
setup({emails}){
|
||||||
let {emailSelection} = useEmailSelection();
|
let {emailSelection} = useEmailSelection();
|
||||||
return { emailSelection }
|
let allSelected = computed(() => {
|
||||||
|
return emails.length == emailSelection.emails.size;
|
||||||
|
})
|
||||||
|
let bulkSelect = function(){
|
||||||
|
if(allSelected.value) {
|
||||||
|
emailSelection.clear();
|
||||||
|
} else {
|
||||||
|
emailSelection.addMultiple(emails)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { emailSelection, allSelected, bulkSelect }
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
emails: {
|
||||||
|
type: Array,
|
||||||
|
default: []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>VMail Inbox</h1>
|
<h1>VMail Inbox</h1>
|
||||||
|
|
||||||
<BulkActionBar />
|
<BulkActionBar :emails="emails" />
|
||||||
|
|
||||||
<MailTable :emails="emails" />
|
<MailTable :emails="emails" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ export const useEmailSelection = function(){
|
|||||||
this.emails.add(id);
|
this.emails.add(id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
clear(){
|
||||||
|
this.emails.clear();
|
||||||
|
},
|
||||||
|
addMultiple(emails) {
|
||||||
|
emails.forEach(email => {
|
||||||
|
this.emails.add(email)
|
||||||
|
})
|
||||||
|
},
|
||||||
forSelected(fn){
|
forSelected(fn){
|
||||||
this.emails.forEach(email => {
|
this.emails.forEach(email => {
|
||||||
fn(email)
|
fn(email)
|
||||||
|
|||||||
Reference in New Issue
Block a user