mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Refactor lots of non-table functionality from MailTable to MailScreen
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<h1>VMail Inbox</h1>
|
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<template #default>
|
<template #default>
|
||||||
<MailTable />
|
<MailScreen />
|
||||||
</template>
|
</template>
|
||||||
<template #fallback>
|
<template #fallback>
|
||||||
Loading...
|
Loading...
|
||||||
@@ -14,12 +12,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MailTable from '@/components/MailTable.vue';
|
import MailScreen from '@/components/MailScreen.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
components: {
|
components: {
|
||||||
MailTable
|
MailScreen
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
41
src/components/MailScreen.vue
Normal file
41
src/components/MailScreen.vue
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<template>
|
||||||
|
<h1>VMail Inbox</h1>
|
||||||
|
|
||||||
|
<BulkActionBar :emails="unarchivedEmails" />
|
||||||
|
|
||||||
|
<MailTable :emails="unarchivedEmails" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import MailTable from '@/components/MailTable.vue';
|
||||||
|
import BulkActionBar from '@/components/BulkActionBar.vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async setup(){
|
||||||
|
let response = await axios.get('http://localhost:3000/emails');
|
||||||
|
let emails = response.data;
|
||||||
|
|
||||||
|
return { emails }
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
BulkActionBar,
|
||||||
|
MailTable
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
sortedEmails(){
|
||||||
|
return this.emails.sort((e1, e2) => {
|
||||||
|
return e1.sentAt < e2.sentAt ? 1 : -1
|
||||||
|
})
|
||||||
|
},
|
||||||
|
unarchivedEmails(){
|
||||||
|
return this.sortedEmails.filter(e => !e.archived)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<BulkActionBar :emails="unarchivedEmails" />
|
|
||||||
<table class="mail-table">
|
<table class="mail-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="email in unarchivedEmails"
|
<tr v-for="email in emails"
|
||||||
:key="email.id"
|
:key="email.id"
|
||||||
:class="[email.read ? 'read': '', 'clickable']"
|
:class="[email.read ? 'read': '', 'clickable']"
|
||||||
@click="openEmail(email)">
|
@click="openEmail(email)">
|
||||||
@@ -30,23 +29,17 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import axios from 'axios';
|
|
||||||
import MailView from '@/components/MailView.vue';
|
import MailView from '@/components/MailView.vue';
|
||||||
import ModalView from '@/components/ModalView.vue';
|
import ModalView from '@/components/ModalView.vue';
|
||||||
import BulkActionBar from '@/components/BulkActionBar.vue';
|
|
||||||
import { useEmailSelection } from '../composition/useEmailSelection';
|
import { useEmailSelection } from '../composition/useEmailSelection';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async setup(){
|
async setup(){
|
||||||
let response = await axios.get('http://localhost:3000/emails');
|
|
||||||
let emails = response.data;
|
|
||||||
let openedEmail = null;
|
let openedEmail = null;
|
||||||
|
|
||||||
let { emailSelection } = useEmailSelection();
|
let { emailSelection } = useEmailSelection();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
format,
|
format,
|
||||||
emails,
|
|
||||||
openedEmail,
|
openedEmail,
|
||||||
emailSelection
|
emailSelection
|
||||||
}
|
}
|
||||||
@@ -54,17 +47,6 @@
|
|||||||
components: {
|
components: {
|
||||||
MailView,
|
MailView,
|
||||||
ModalView,
|
ModalView,
|
||||||
BulkActionBar
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
unarchivedEmails(){
|
|
||||||
return this.sortedEmails.filter(e => !e.archived)
|
|
||||||
},
|
|
||||||
sortedEmails(){
|
|
||||||
return this.emails.sort((e1, e2) => {
|
|
||||||
return e1.sentAt < e2.sentAt ? 1 : -1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
openEmail(email){
|
openEmail(email){
|
||||||
@@ -86,11 +68,16 @@
|
|||||||
if(closeModal) { this.openedEmail = null; return null; }
|
if(closeModal) { this.openedEmail = null; return null; }
|
||||||
|
|
||||||
if(indexChange) {
|
if(indexChange) {
|
||||||
let emails = this.unarchivedEmails
|
let index = this.emails.findIndex(e => e == email);
|
||||||
let index = emails.findIndex(e => e == email);
|
this.openEmail(this.emails[index + indexChange])
|
||||||
this.openEmail(emails[index + indexChange])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
emails: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user