mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 23:51:25 +00:00
opening an email below the table
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="[email.read ? 'read': '', 'clickable']"
|
:class="[email.read ? 'read': '', 'clickable']"
|
||||||
@click="readEmail(email)">
|
@click="openEmail(email)">
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" />
|
<input type="checkbox" />
|
||||||
</td>
|
</td>
|
||||||
@@ -17,21 +17,29 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<MailView :email="openedEmail" v-if="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 response = await axios.get('http://localhost:3000/emails');
|
let response = await axios.get('http://localhost:3000/emails');
|
||||||
let emails = response.data;
|
let emails = response.data;
|
||||||
|
let openedEmail = null;
|
||||||
return {
|
return {
|
||||||
format,
|
format,
|
||||||
emails
|
emails,
|
||||||
|
openedEmail
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
components: {
|
||||||
|
MailView
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
unarchivedEmails(){
|
unarchivedEmails(){
|
||||||
return this.sortedEmails.filter(e => !e.archived)
|
return this.sortedEmails.filter(e => !e.archived)
|
||||||
@@ -43,9 +51,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
readEmail(email){
|
openEmail(email){
|
||||||
email.read = true
|
email.read = true
|
||||||
axios.put(`http://localhost:3000/emails/${email.id}`, email)
|
axios.put(`http://localhost:3000/emails/${email.id}`, email)
|
||||||
|
this.openedEmail = email;
|
||||||
},
|
},
|
||||||
archiveEmail(email){
|
archiveEmail(email){
|
||||||
email.archived = true;
|
email.archived = true;
|
||||||
|
|||||||
31
src/components/MailView.vue
Normal file
31
src/components/MailView.vue
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<template>
|
||||||
|
<div class="email-display" v-if="email">
|
||||||
|
<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