mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-22 07:05:20 +00:00
Video 5 - MailView
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<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="readEmail(email)">
|
@click="openEmail(email)">
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" />
|
<input type="checkbox" />
|
||||||
</td>
|
</td>
|
||||||
@@ -17,20 +17,26 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<MailView v-if="openedEmail" :email="openedEmail" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import MailView from '@/components/MailView.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')
|
||||||
return {
|
return {
|
||||||
format,
|
format,
|
||||||
emails
|
emails,
|
||||||
|
openedEmail: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
components: {
|
||||||
|
MailView
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
sortedEmails() {
|
sortedEmails() {
|
||||||
return this.emails.sort((e1, e2) => {
|
return this.emails.sort((e1, e2) => {
|
||||||
@@ -42,9 +48,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
readEmail(email) {
|
openEmail(email) {
|
||||||
email.read = true
|
email.read = true
|
||||||
this.updateEmail(email)
|
this.updateEmail(email)
|
||||||
|
this.openedEmail = email
|
||||||
},
|
},
|
||||||
archiveEmail(email) {
|
archiveEmail(email) {
|
||||||
email.archived = true
|
email.archived = true
|
||||||
|
|||||||
30
src/components/MailView.vue
Normal file
30
src/components/MailView.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<template>
|
||||||
|
<div class="email-display">
|
||||||
|
<h2 class="mb-0">Subject: <strong>{{email.subject}}</strong></h2>
|
||||||
|
<div><em>From {{email.from}} on {{format(new Date(email.sentAt), 'MMM do yyyy')}}</em></div>
|
||||||
|
<div v-html="marked(email.body)" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { format } from 'date-fns'
|
||||||
|
import marked from 'marked'
|
||||||
|
export default {
|
||||||
|
setup(){
|
||||||
|
return {
|
||||||
|
format,
|
||||||
|
marked
|
||||||
|
}
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
email: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user