Select multiple emails using checkboxes

This commit is contained in:
Jeffrey Biles
2020-03-17 19:18:23 -07:00
parent 53383058d9
commit d594a9fdd1
2 changed files with 17 additions and 2 deletions

View File

@@ -7,6 +7,9 @@ new Server({
}, },
factories: { factories: {
email: Factory.extend({ email: Factory.extend({
id(i) {
return i;
},
from(){ from(){
return faker.internet.email() return faker.internet.email()
}, },

View File

@@ -1,11 +1,14 @@
<template> <template>
<table> <table>
Number selected: {{selectedEmailIds.size}}
<thead> <thead>
</thead> </thead>
<tbody> <tbody>
<tr v-for="email in emails" :key="email.id" :class="[email.read ? 'read' : '']"> <tr v-for="email in emails" :key="email.id" :class="[email.read ? 'read' : '']">
<td><input type="checkbox" /></td> <td><input type="checkbox"
:checked="selectedEmailIds.has(email.id)"
@click="addToSelectedEmails(email.id)" /></td>
<td>{{email.from}}</td> <td>{{email.from}}</td>
<td> <td>
<p><strong>{{email.subject}}</strong> - {{email.body}}</p> <p><strong>{{email.subject}}</strong> - {{email.body}}</p>
@@ -18,9 +21,18 @@
<script> <script>
import { format } from 'date-fns' import { format } from 'date-fns'
import { ref } from 'vue';
export default { export default {
setup(){ setup(){
return {format} let selectedEmailIds = ref(new Set(['1', '5']))
let addToSelectedEmails = (id) => {
if(selectedEmailIds.value.has(id)) {
selectedEmailIds.value.delete(id)
} else {
selectedEmailIds.value.add(id);
}
}
return {format, selectedEmailIds, addToSelectedEmails}
}, },
props: { props: {
emails: { emails: {