1
1
<template >
2
- <section class =" c-emails" tid =" emails" >
3
- <h1 class =" c-emails__header" tid =" emails__header" key =" emails-header" v-if =" hasUnreadEmails" >You have {{ unreadEmails.length }} new emails:</h1 >
4
- <h1 class =" c-emails__header" tid =" emails__header" key =" emails-header" v-else >You have no unread emails</h1 >
5
- <ul class =" c-emails__list" tid =" emails__list" >
6
- <li class =" c-emails__list-item c-email" :class =" { 'c-email--unread': email.unread }" v-for =" email in emails" :key =" email.id" tid =" email" >
7
- <div class =" c-email__subject" :class =" { 'c-email__subject--unread': email.unread }" @click =" toggleEmail(email)" tid =" email__subject" >{{ email.subject }}</div >
8
- <em class =" c-email__sender" tid =" email__sender" >from {{ email.sender }}</em >
9
- <div class =" c-email__body" v-show =" openEmailId === email.id" tid =" email__body" >{{ email.body }}</div >
10
- </li >
11
- </ul >
2
+ <section class =" c-emails" tid =" c-emails" >
3
+ <h1 class =" c-emails__header" tid =" c-emails__header" v-if =" hasUnreadEmails" >You have {{ unreadEmails.length }} new emails:</h1 >
4
+ <h1 class =" c-emails__header" tid =" c-emails__header" v-else >You have no unread emails</h1 >
5
+ <my-checkbox-list >
6
+ <ul class =" c-emails__list" tid =" c-emails__list" >
7
+ <li class =" c-emails-list-item c-email" :class =" { 'c-email--unread': email.unread }" v-for =" email in emailsToDisplay" :key =" email.id" tid =" c-email" >
8
+ <my-checkbox class =" c-emails-list-item__checkbox" tid =" c-emails-list-item__checkbox" v-model =" email.selected" ></my-checkbox >
9
+ <div class =" c-emails-list-item__content" >
10
+ <div class =" c-email__subject" :class =" { 'c-email__subject--unread': email.unread }" @click =" toggleEmail(email)" tid =" c-email__subject" >{{ email.subject }}</div >
11
+ <em class =" c-email__sender" tid =" c-email__sender" >from {{ email.sender }}</em >
12
+ <div class =" c-email__body" v-show =" openEmailId === email.id" tid =" c-email__body" >{{ email.body }}</div >
13
+ </div >
14
+ </li >
15
+ </ul >
16
+ <my-checkbox-list-status >
17
+ <template slot-scope="{ numberOfCheckboxes, numberOfSelectedCheckboxes }">
18
+ <div v-if =" numberOfSelectedCheckboxes > 0" >
19
+ {{ numberOfSelectedCheckboxes }} of {{ numberOfCheckboxes }} emails have been selected.
20
+ <a href =" " class =" c-emails__action" @click.prevent =" selectAll()" v-if =" numberOfSelectedCheckboxes !== numberOfCheckboxes" >Select all</a >
21
+ <a href =" " class =" c-emails__action" @click.prevent =" deselectAll()" v-if =" numberOfSelectedCheckboxes !== 0" >Deselect all</a >
22
+ </div >
23
+ <div v-else >
24
+ No emails have been selected.
25
+ <a href =" " class =" c-emails__action" @click.prevent =" selectAll()" >Select all</a >
26
+ </div >
27
+ </template >
28
+ </my-checkbox-list-status >
29
+ </my-checkbox-list >
12
30
</section >
13
31
</template >
14
32
15
33
<script >
16
34
import Vue from ' vue' ;
17
- import { Component , Prop } from ' vue-property-decorator' ;
35
+ import { Component , Prop , Watch } from ' vue-property-decorator' ;
18
36
19
- @Component
37
+ import MyCheckbox from ' ./MyCheckbox' ;
38
+ import MyCheckboxList from ' ./MyCheckboxList' ;
39
+ import MyCheckboxListStatus from ' ./MyCheckboxListStatus' ;
40
+
41
+ @Component ({
42
+ components: { MyCheckbox, MyCheckboxList, MyCheckboxListStatus }
43
+ })
20
44
export default class Dashboard extends Vue {
21
45
@Prop ({ type: Array , default : () => [] }) emails;
22
46
23
47
openEmailId = null ;
48
+ emailsToDisplay = [];
24
49
25
50
get unreadEmails () {
26
51
return this .emails .filter (e => e .unread );
@@ -30,6 +55,11 @@ export default class Dashboard extends Vue {
30
55
return this .unreadEmails .length > 0 ;
31
56
}
32
57
58
+ @Watch (' emails' , { immediate: true })
59
+ onEmailsUpdated () {
60
+ this .emailsToDisplay = this .emails .map (email => ({ ... email, selected: false }));
61
+ }
62
+
33
63
toggleEmail (email ) {
34
64
if (this .openEmailId === email .id ) {
35
65
this .openEmailId = null ;
@@ -38,6 +68,18 @@ export default class Dashboard extends Vue {
38
68
this .openEmailId = email .id ;
39
69
}
40
70
}
71
+
72
+ selectAll () {
73
+ for (let email of this .emailsToDisplay ) {
74
+ email .selected = true ;
75
+ }
76
+ }
77
+
78
+ deselectAll () {
79
+ for (let email of this .emailsToDisplay ) {
80
+ email .selected = false ;
81
+ }
82
+ }
41
83
}
42
84
</script >
43
85
@@ -48,13 +90,26 @@ export default class Dashboard extends Vue {
48
90
padding : 0 ;
49
91
}
50
92
93
+ .c-emails__action + .c-emails__action {
94
+ margin-left : 0.5rem ;
95
+ }
96
+
51
97
.c-email {
52
- display : block ;
98
+ display : flex ;
99
+ align-items : center ;
100
+ }
101
+
102
+ .c-emails-list-item__checkbox {
103
+ padding : 0 1rem ;
104
+ }
105
+
106
+ .c-emails-list-item__content {
53
107
padding : 1rem 2.5rem 1rem 6rem ;
54
108
position : relative ;
109
+ flex-grow : 1 ;
55
110
}
56
111
57
- .c-email :before {
112
+ .c-emails-list-item__content :before {
58
113
content : " ✉" ;
59
114
font-size : 6rem ;
60
115
line-height : 6rem ;
0 commit comments