Lesson 9 - Email Navigation Buttons and Keyboard Shortcuts

This commit is contained in:
Jeffrey Biles
2020-07-11 11:38:29 -07:00
parent d3fc83dd9c
commit aa8b4c6244
2 changed files with 30 additions and 2 deletions

View File

@@ -55,6 +55,7 @@
openEmail(email) {
email.read = true
this.updateEmail(email)
this.openedEmail = email
},
archiveEmail(email) {

View File

@@ -1,5 +1,11 @@
<template>
<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>
<div><em>From {{email.from}} on {{format(new Date(email.sentAt), 'MMM do yyyy')}}</em></div>
<div v-html="marked(email.body)" />
@@ -9,11 +15,32 @@
<script>
import { format } from 'date-fns'
import marked from 'marked'
import axios from 'axios'
import useKeydown from '../composables/use-keydown'
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 {
format,
marked
marked,
toggleRead,
toggleArchive
}
},
props: {