Skip to content

Commit a6241d0

Browse files
Erika Perugachinot-gabriel
authored andcommitted
Update badge (#232)
* update unread to emails and thread * Update badge. Resolve #148 * Update snapshots and add test * Review
1 parent 1c30b09 commit a6241d0

File tree

22 files changed

+253
-141
lines changed

22 files changed

+253
-141
lines changed

electron_app/src/DBManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ const baseThreadQuery = ({
425425
Table.CONTACT
426426
}.email END)) as fromContactName`
427427
),
428-
db.raw(`max(${Table.EMAIL}.unread) as isUnread`)
428+
db.raw(`max(${Table.EMAIL}.unread) as unread`)
429429
)
430430
.from(Table.EMAIL)
431431
.leftJoin(

email_mailbox/public/labels.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
{
44
"id": 1,
55
"color": "#ffffff",
6-
"text": "Inbox"
6+
"text": "Inbox",
7+
"badge": 1
78
},
89
{
910
"id": 2,
@@ -13,7 +14,8 @@
1314
{
1415
"id": 3,
1516
"color": "#ffffff",
16-
"text": "Spam"
17+
"text": "Spam",
18+
"badge": 1
1719
},
1820
{
1921
"id": 4,

email_mailbox/src/actions/emails.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Email } from './types';
22
import {
33
getEmailsByThreadId,
4+
updateUnreadEmailByThreadId,
45
setMuteEmailById,
56
setUnreadEmailById
67
} from '../utils/electronInterface';
78
import { loadContacts } from './contacts';
9+
import { updateLabelSuccess } from './labels';
810

911
export const addEmails = emails => {
1012
return {
@@ -81,3 +83,16 @@ export const markEmailUnread = (emailId, valueToSet) => {
8183
}
8284
};
8385
};
86+
87+
export const updateUnreadEmails = (thread, label) => {
88+
return async dispatch => {
89+
try {
90+
await updateUnreadEmailByThreadId(thread.id, thread.unread);
91+
if (label) {
92+
dispatch(updateLabelSuccess(label));
93+
}
94+
} catch (e) {
95+
// To do
96+
}
97+
};
98+
};

email_mailbox/src/actions/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {
77
filterThreadsByUnread,
88
loadEvents,
99
loadThreads,
10-
markThreadsRead,
1110
moveThreads,
1211
multiSelectThread,
1312
selectThread,
1413
removeThread,
1514
removeThreadLabel,
1615
deselectThreads,
16+
updateUnreadThread,
17+
updateUnreadThreads,
1718
searchThreads,
1819
selectThreads,
1920
removeThreads,
@@ -24,7 +25,8 @@ import {
2425
loadEmails,
2526
markEmailUnread,
2627
muteEmail,
27-
muteNotifications
28+
muteNotifications,
29+
updateUnreadEmails
2830
} from './emails';
2931
import {
3032
addLabels,
@@ -65,7 +67,6 @@ export {
6567
loadThreads,
6668
markEmailUnread,
6769
markFeedAsSelected,
68-
markThreadsRead,
6970
moveThreads,
7071
multiSelectThread,
7172
muteEmail,
@@ -83,5 +84,8 @@ export {
8384
setThreads,
8485
toggleMuteFeed,
8586
updateLabel,
86-
updateLabelSuccess
87+
updateLabelSuccess,
88+
updateUnreadEmails,
89+
updateUnreadThread,
90+
updateUnreadThreads
8791
};

email_mailbox/src/actions/threads.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Thread } from './types';
22
import { startLoadSync, stopLoadSync } from './activity';
3+
import { updateLabelSuccess } from './labels';
34
import {
45
createEmailLabel,
56
deleteEmailLabel,
@@ -106,7 +107,20 @@ export const moveThreads = (threadIds, labelId) => ({
106107
labelId
107108
});
108109

109-
export const markThreadsRead = (threadsParams, read) => {
110+
export const updateUnreadThread = thread => {
111+
return {
112+
type: Thread.UPDATE_UNREAD_THREAD,
113+
thread
114+
};
115+
};
116+
117+
export const updateUnreadThreadsSuccess = (threadsIds, read) => ({
118+
threadsIds,
119+
read,
120+
type: Thread.UPDATE_UNREAD_THREADS
121+
});
122+
123+
export const updateUnreadThreads = (threadsParams, read, label) => {
110124
return async dispatch => {
111125
try {
112126
const storeIds = threadsParams.map(param => param.threadIdStore);
@@ -117,20 +131,15 @@ export const markThreadsRead = (threadsParams, read) => {
117131
})
118132
);
119133
if (dbReponse) {
120-
dispatch(markThreadsReadSuccess(storeIds, read));
134+
dispatch(updateUnreadThreadsSuccess(storeIds, read));
135+
if (label) dispatch(updateLabelSuccess(label));
121136
}
122137
} catch (e) {
123138
// To do
124139
}
125140
};
126141
};
127142

128-
export const markThreadsReadSuccess = (threadsIds, read) => ({
129-
threadsIds,
130-
read,
131-
type: Thread.UPDATE_UNREAD
132-
});
133-
134143
export const searchThreads = params => {
135144
return async dispatch => {
136145
try {

email_mailbox/src/actions/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const Thread = {
1313
REMOVE_THREADS: 'REMOVE_THREADS',
1414
SEARCH_THREADS: 'SEARCH_THREADS',
1515
MOVE_THREADS: 'MOVE_THREADS',
16-
UPDATE_UNREAD: 'UPDATE_UNREAD_THREADS'
16+
UPDATE_UNREAD_THREADS: 'UPDATE_UNREAD_THREADS',
17+
UPDATE_UNREAD_THREAD: 'UPDATE_UNREAD_THREAD'
1718
};
1819

1920
export const Contact = {

email_mailbox/src/components/EmailWrapper.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ class EmailWrapper extends Component {
1313
};
1414
}
1515

16-
componentDidMount() {
17-
const email = this.props.email;
18-
if (email.unread && (this.state.displayEmail || this.props.staticOpen)) {
19-
this.props.markUnread();
20-
}
21-
}
22-
23-
componentWillReceiveProps(nextProps) {
24-
const email = nextProps.email;
25-
if (email.unread && (this.state.displayEmail || this.props.staticOpen)) {
26-
this.props.markUnread();
27-
}
28-
}
29-
3016
render() {
3117
return (
3218
<Email
@@ -43,6 +29,14 @@ class EmailWrapper extends Component {
4329
);
4430
}
4531

32+
componentDidMount() {
33+
if (this.props.email.unread) {
34+
this.setState({
35+
displayEmail: true
36+
});
37+
}
38+
}
39+
4640
onToggleEmail = () => {
4741
if (!this.props.staticOpen) {
4842
this.setState({
@@ -74,7 +68,6 @@ class EmailWrapper extends Component {
7468
EmailWrapper.propTypes = {
7569
displayEmail: PropTypes.func,
7670
email: PropTypes.object,
77-
markUnread: PropTypes.func,
7871
staticOpen: PropTypes.bool
7972
};
8073

email_mailbox/src/components/PanelWrapper.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class PanelWrapper extends Component {
3838
limit: this.props.threadsCount + 1
3939
});
4040
}
41+
this.props.onUpdateUnreadEmails();
4142
});
4243

4344
addEvent(Event.UPDATE_SAVED_DRAFTS, () => {
@@ -145,8 +146,9 @@ class PanelWrapper extends Component {
145146

146147
PanelWrapper.propTypes = {
147148
onLoadThreads: PropTypes.func,
148-
threadsCount: PropTypes.number,
149-
onUpdateOpenedAccount: PropTypes.func
149+
onUpdateOpenedAccount: PropTypes.func,
150+
onUpdateUnreadEmails: PropTypes.func,
151+
threadsCount: PropTypes.number
150152
};
151153

152154
export default PanelWrapper;

email_mailbox/src/components/Thread.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ class Thread extends Component {
3636

3737
componentDidMount() {
3838
this.props.onLoadEmails(this.props.thread.threadId);
39-
this.props.onMarkRead(this.props.thread, true);
39+
if (this.props.thread.unread) {
40+
this.props.onUpdateUnreadEmails(this.props.thread, false);
41+
}
42+
}
43+
44+
componentWillUnmount() {
45+
if (this.props.thread.unread) {
46+
this.props.onUpdateUnreadThread(this.props.thread, false);
47+
}
4048
}
4149

4250
handleRemoveLabel = labelId => {
@@ -48,7 +56,8 @@ Thread.propTypes = {
4856
emails: PropTypes.object,
4957
labels: PropTypes.array,
5058
onLoadEmails: PropTypes.func,
51-
onMarkRead: PropTypes.func,
59+
onUpdateUnreadEmails: PropTypes.func,
60+
onUpdateUnreadThread: PropTypes.func,
5261
onRemoveThreadLabel: PropTypes.func,
5362
thread: PropTypes.object
5463
};

email_mailbox/src/components/ThreadItem.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class ThreadItem extends Component {
1010
render() {
1111
const visibleStyle = this.getStyleVisibilityByMultiselect();
1212
const {
13+
checked,
1314
thread,
14-
myClass,
1515
onRegionEnter,
1616
onRegionLeave,
1717
onSelectThread,
@@ -20,7 +20,11 @@ class ThreadItem extends Component {
2020
} = this.props;
2121
return (
2222
<div
23-
className={'thread-item-container ' + myClass}
23+
className={
24+
'thread-item-container ' +
25+
(thread.unread ? 'thread-unread' : 'thread-read') +
26+
(checked ? ' thread-checked' : '')
27+
}
2428
onClick={() => {
2529
onSelectThread(thread);
2630
}}
@@ -253,10 +257,6 @@ HoverMenuItem.propTypes = {
253257
tip: PropTypes.string
254258
};
255259

256-
ThreadItem.defaultProps = {
257-
myClass: ''
258-
};
259-
260260
ThreadItem.propTypes = {
261261
color: PropTypes.string,
262262
checked: PropTypes.bool,
@@ -268,7 +268,6 @@ ThreadItem.propTypes = {
268268
letters: PropTypes.string,
269269
mailbox: PropTypes.string,
270270
multiselect: PropTypes.bool,
271-
myClass: PropTypes.string,
272271
onCheckItem: PropTypes.func,
273272
onImportantClick: PropTypes.func,
274273
onMouseEnterItem: PropTypes.func,

0 commit comments

Comments
 (0)