mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 23:51:25 +00:00
Lesson 11 - Reactive Sets
This commit is contained in:
@@ -1,18 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<h1>{{emailSelection.emails.size}} emails selected</h1>
|
||||||
<table class="mail-table">
|
<table class="mail-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="email in unarchivedEmails"
|
<tr v-for="email in unarchivedEmails"
|
||||||
:key="email.id"
|
:key="email.id"
|
||||||
:class="['clickable', email.read ? 'read' : '']"
|
:class="['clickable', email.read ? 'read' : '']">
|
||||||
@click="openEmail(email)">
|
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" />
|
<input type="checkbox"
|
||||||
|
@click="emailSelection.toggle(email)"
|
||||||
|
:selected="emailSelection.emails.has(email)" />
|
||||||
</td>
|
</td>
|
||||||
<td>{{email.from}}</td>
|
<td @click="openEmail(email)">{{email.from}}</td>
|
||||||
<td>
|
<td @click="openEmail(email)">
|
||||||
<p><strong>{{email.subject}}</strong> - {{email.body}}</p>
|
<p><strong>{{email.subject}}</strong> - {{email.body}}</p>
|
||||||
</td>
|
</td>
|
||||||
<td class="date">{{format(new Date(email.sentAt), 'MMM do yyyy')}}</td>
|
<td class="date" @click="openEmail(email)">
|
||||||
|
{{format(new Date(email.sentAt), 'MMM do yyyy')}}
|
||||||
|
</td>
|
||||||
<td><button @click="archiveEmail(email)">Archive</button></td>
|
<td><button @click="archiveEmail(email)">Archive</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -27,11 +31,26 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import MailView from '@/components/MailView.vue';
|
import MailView from '@/components/MailView.vue';
|
||||||
import ModalView from '@/components/ModalView.vue';
|
import ModalView from '@/components/ModalView.vue';
|
||||||
|
import { reactive } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async setup(){
|
async setup(){
|
||||||
let {data: emails} = await axios.get('http://localhost:3000/emails')
|
let {data: emails} = await axios.get('http://localhost:3000/emails')
|
||||||
|
|
||||||
|
let selected = reactive(new Set())
|
||||||
|
let emailSelection = {
|
||||||
|
emails: selected,
|
||||||
|
toggle(email) {
|
||||||
|
if(selected.has(email)) {
|
||||||
|
selected.delete(email)
|
||||||
|
} else {
|
||||||
|
selected.add(email)
|
||||||
|
}
|
||||||
|
console.log(selected)
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
|
emailSelection,
|
||||||
format,
|
format,
|
||||||
emails,
|
emails,
|
||||||
openedEmail: null
|
openedEmail: null
|
||||||
|
|||||||
Reference in New Issue
Block a user