mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-22 07:05:20 +00:00
Lesson 9 - Email Navigation Buttons and Keyboard Shortcuts
This commit is contained in:
@@ -55,6 +55,7 @@
|
|||||||
openEmail(email) {
|
openEmail(email) {
|
||||||
email.read = true
|
email.read = true
|
||||||
this.updateEmail(email)
|
this.updateEmail(email)
|
||||||
|
|
||||||
this.openedEmail = email
|
this.openedEmail = email
|
||||||
},
|
},
|
||||||
archiveEmail(email) {
|
archiveEmail(email) {
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="email-display">
|
<div class="email-display">
|
||||||
|
<div>
|
||||||
|
<button @click="toggleArchive">{{email.archived ? 'Move to Inbox (e)' : 'Archive (e)'}}</button>
|
||||||
|
<button @click="toggleRead">{{email.read ? 'Mark Unread (r)' : 'Mark Read (r)'}}</button>
|
||||||
|
<button @click="goNewer">Newer (k)</button>
|
||||||
|
<button @click="goOlder">Older (j)</button>
|
||||||
|
</div>
|
||||||
<h2 class="mb-0">Subject: <strong>{{email.subject}}</strong></h2>
|
<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><em>From {{email.from}} on {{format(new Date(email.sentAt), 'MMM do yyyy')}}</em></div>
|
||||||
<div v-html="marked(email.body)" />
|
<div v-html="marked(email.body)" />
|
||||||
@@ -9,11 +15,32 @@
|
|||||||
<script>
|
<script>
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import marked from 'marked'
|
import marked from 'marked'
|
||||||
|
import axios from 'axios'
|
||||||
|
import useKeydown from '../composables/use-keydown'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup(){
|
setup(props, {emit}){
|
||||||
|
let email = props.email;
|
||||||
|
let toggleRead = () => {
|
||||||
|
email.read = !email.read
|
||||||
|
axios.put(`http://localhost:3000/emails/${email.id}`, email)
|
||||||
|
}
|
||||||
|
let toggleArchive = () => {
|
||||||
|
email.archived = !email.archived
|
||||||
|
axios.put(`http://localhost:3000/emails/${email.id}`, email)
|
||||||
|
// How to close the modal?
|
||||||
|
}
|
||||||
|
|
||||||
|
useKeydown([
|
||||||
|
{key: 'r', fn: toggleRead},
|
||||||
|
{key: 'e', fn: toggleArchive}
|
||||||
|
])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
format,
|
format,
|
||||||
marked
|
marked,
|
||||||
|
toggleRead,
|
||||||
|
toggleArchive
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
Reference in New Issue
Block a user