Skip to content

Commit 169c397

Browse files
author
Jeffrey Biles
committed
Save email when toggling read/unread and inbox/archived
1 parent 3842b5a commit 169c397

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

db.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
"body": "First of all, lets congratulate Kia King Ishii on joining the Vue.js core team! 🎉 He has been doing an incredible job building vuex-orm and will now focus on working on the next versions of Vuex.\n\nSpeaking of which – Vuex v4.0.0-alpha.1 has just been released! This is the version of Vuex that will work with Vue 3.0 but keep the familiar API you know from the current version.",
2626
"sentAt": "2020-03-18T18:25:43.511Z",
2727
"archived": false,
28-
"read": false
28+
"read": true
2929
},
3030
{
3131
"id": 4,
3232
"from": "[email protected]",
3333
"subject": "'Vue 3 Release Roadmap' + 6 more must-read articles from this week",
3434
"body": "Newsletter Issue #161",
3535
"sentAt": "2020-03-24T18:25:43.511Z",
36-
"archived": false,
36+
"archived": true,
3737
"read": true
3838
}
3939
]

src/components/MailTable.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<tr v-for="email in emails"
55
:key="email.id"
66
:class="[email.read ? 'read' : '']"
7-
@click="openEmail(email)"
7+
@click="openEmail(email, true)"
88
class="clickable">
99
<td>
1010
<input type="checkbox"
@@ -20,7 +20,9 @@
2020
</tbody>
2121

2222
<ModalView v-if="!!openedEmail" :closeModal="() => {openedEmail = null;}">
23-
<MailView :email="openedEmail" @changeEmail="(args) => changeEmail(emails, args)" />
23+
<MailView :email="openedEmail"
24+
@changeEmail="(args) => changeEmail(emails, args)"
25+
@openEmail="openEmail" />
2426
</ModalView>
2527
</table>
2628
</template>
@@ -47,13 +49,21 @@
4749
}
4850
}
4951
50-
function changeEmail(emails, {amount, toggleArchive, closeModal}){
52+
function changeEmail(emails, {amount, toggleArchive, closeModal, toggleRead}){
5153
let index = emails.findIndex(e => e == openedEmail.value);
5254
5355
if(toggleArchive) { emails[index].archived = !emails[index].archived }
56+
if(toggleRead) { emails[index].read = !emails[index].read }
57+
58+
if(toggleArchive || toggleRead) {
59+
axios.put(`http://localhost:3000/emails/${emails[index].id}`, emails[index])
60+
}
61+
5462
if(closeModal) { openedEmail.value = null; return null; }
5563
56-
openEmail(emails[index + amount])
64+
if(amount) {
65+
openEmail(emails[index + amount])
66+
}
5767
}
5868
5969
return {format, emailSelection, openedEmail, openEmail, changeEmail}

src/components/MailView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<button @click="toggleArchive">{{email.archived ? 'Move to Inbox' : 'Archive'}}</button>
55
<button @click="goNewer">Newer</button>
66
<button @click="goOlder">Older</button>
7-
<button @click="toggleRead(email)">Mark {{email.read ? 'Unread' : 'Read'}}</button>
7+
<button @click="toggleRead()">Mark {{email.read ? 'Unread' : 'Read'}}</button>
88
</div>
99

1010
<h2 class="mb-0">Subject: <strong>{{email.subject}}</strong></h2>
@@ -25,7 +25,7 @@
2525
let goNewerAndArchive = () => emit('changeEmail', {amount: -1, toggleArchive: true})
2626
let goOlderAndArchive = () => emit('changeEmail', {amount: 1, toggleArchive: true})
2727
let toggleArchive = () => emit('changeEmail', {toggleArchive: true, closeModal: true})
28-
let toggleRead = (email) => { email.read = !email.read }
28+
let toggleRead = () => { emit('changeEmail', {toggleRead: true}) }
2929
3030
useKeydown([
3131
{key: 'k', fn: goNewer},

0 commit comments

Comments
 (0)