Skip to content

Commit ff5d738

Browse files
Fix scroll and replace componentDidUpdate instead of componentWillProps. Close #1086
1 parent ca4700e commit ff5d738

File tree

4 files changed

+65
-47
lines changed

4 files changed

+65
-47
lines changed

email_mailbox/src/components/PanelWrapper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ class PanelWrapper extends Component {
296296
.threadIdSelected;
297297
const currentLabelId = this.state.sectionSelected.params.mailboxSelected
298298
.id;
299-
const limit =
300-
this.props.threadsCount > 20 ? this.props.threadsCount : undefined;
299+
const currentMailboxSize = this.props[currentLabelId];
300+
const limit = currentMailboxSize > 22 ? currentMailboxSize : undefined;
301301
if (labelIds && isRenderingMailbox) {
302302
if (labelIds.includes(currentLabelId)) {
303303
this.props.onLoadThreads(

email_mailbox/src/components/Threads.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ const Threads = props => (
6565
</span>
6666
</div>
6767
</div>
68-
<div className="threads-content cptx-scrollbar" onScroll={props.onScroll}>
68+
<div
69+
className="threads-content cptx-scrollbar"
70+
onScroll={props.onScroll}
71+
ref={props.setScrollRef}
72+
>
6973
<div className="threads-items">
7074
{props.threads.size < 1 && (
7175
<EmptyMailbox
@@ -175,6 +179,7 @@ Threads.propTypes = {
175179
popupContent: PropTypes.object,
176180
searchParams: PropTypes.object,
177181
setPopupContent: PropTypes.func,
182+
setScrollRef: PropTypes.func,
178183
switchChecked: PropTypes.bool,
179184
switchDisabled: PropTypes.bool,
180185
threadItemsChecked: PropTypes.object,

email_mailbox/src/components/ThreadsWrapper.js

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,7 @@ class ThreadsWrapper extends Component {
1616
tip: '',
1717
popupContent: undefined
1818
};
19-
}
20-
21-
componentWillReceiveProps(nextProps) {
22-
if (
23-
this.props.mailboxSelected !== nextProps.mailboxSelected ||
24-
this.props.searchParams !== nextProps.searchParams ||
25-
(nextProps.threadItemsChecked.size === 0 &&
26-
this.props.threadItemsChecked.size > 0)
27-
) {
28-
this.setState({ lastMinDate: undefined });
29-
this.props.onLoadThreads(
30-
nextProps.mailboxSelected,
31-
true,
32-
nextProps.searchParams
33-
);
34-
}
35-
if (
36-
this.props.threadItemsChecked.size > 0 &&
37-
this.props.mailboxSelected !== nextProps.mailboxSelected
38-
) {
39-
this.props.onBackOption();
40-
}
41-
42-
if (
43-
this.state.isHiddenLoadingSync &&
44-
nextProps.totalTask > nextProps.completedTask
45-
) {
46-
this.setState({ isHiddenLoadingSync: false });
47-
}
48-
if (
49-
!this.state.isHiddenLoadingSync &&
50-
nextProps.totalTask > 0 &&
51-
nextProps.completedTask > 0 &&
52-
(nextProps.totalTask === nextProps.completedTask ||
53-
nextProps.completedTask > nextProps.totalTask)
54-
) {
55-
setTimeout(() => this.setState({ isHiddenLoadingSync: true }), 1000);
56-
}
19+
this.scroll = null;
5720
}
5821

5922
render() {
@@ -68,6 +31,7 @@ class ThreadsWrapper extends Component {
6831
onMouseLeaveItem={this.handleMouseLeaveItem}
6932
onScroll={this.handleScroll}
7033
onChangeSwitch={this.handleChangeSwitch}
34+
setScrollRef={this.handleSetScrollRef}
7135
tip={this.state.tip}
7236
popupContent={this.state.popupContent}
7337
setPopupContent={this.setPopupContent}
@@ -82,6 +46,46 @@ class ThreadsWrapper extends Component {
8246
this.props.onLoadApp(this.props.mailboxSelected, true);
8347
}
8448

49+
componentDidUpdate(prevProps) {
50+
if (
51+
prevProps.mailboxSelected !== this.props.mailboxSelected ||
52+
prevProps.searchParams !== this.props.searchParams ||
53+
(this.props.threadItemsChecked.size === 0 &&
54+
prevProps.threadItemsChecked.size > 0)
55+
) {
56+
this.setState({ lastMinDate: undefined });
57+
this.props.onLoadThreads(
58+
this.props.mailboxSelected,
59+
true,
60+
this.props.searchParams
61+
);
62+
if (this.scroll.scrollTop !== 0) {
63+
this.scroll.scrollTop = 0;
64+
}
65+
}
66+
if (
67+
this.props.threadItemsChecked.size > 0 &&
68+
prevProps.mailboxSelected !== this.props.mailboxSelected
69+
) {
70+
this.props.onBackOption();
71+
}
72+
if (
73+
this.state.isHiddenLoadingSync &&
74+
this.props.totalTask > this.props.completedTask
75+
) {
76+
this.setState({ isHiddenLoadingSync: false });
77+
}
78+
if (
79+
!this.state.isHiddenLoadingSync &&
80+
this.props.totalTask > 0 &&
81+
this.props.completedTask > 0 &&
82+
(this.props.totalTask === this.props.completedTask ||
83+
this.props.completedTask > this.props.totalTask)
84+
) {
85+
setTimeout(() => this.setState({ isHiddenLoadingSync: true }), 1000);
86+
}
87+
}
88+
8589
handleCloseMessage = () => {
8690
if (this.props.isUpdateAvailable) {
8791
this.props.onCloseUpdateMessage();
@@ -159,6 +163,10 @@ class ThreadsWrapper extends Component {
159163
this.setState({ popupContent: undefined }, this.props.onEmptyTrash);
160164
};
161165

166+
handleSetScrollRef = e => {
167+
this.scroll = e;
168+
};
169+
162170
setPopupContent = popupContent => {
163171
this.setState({ popupContent });
164172
};

email_mailbox/src/containers/Panel.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ import { updateSettings } from '../utils/ipc';
1919
import { defineRejectedLabels } from '../utils/EmailUtils';
2020

2121
const mapStateToProps = state => {
22-
const threadsCount = state
22+
const labelIds = state
2323
.get('threads')
24-
.get(`${LabelType.inbox.id}`)
25-
.get('list').size;
26-
return {
27-
threadsCount
28-
};
24+
.keySeq()
25+
.toArray();
26+
const result = labelIds.reduce((result, id) => {
27+
const size = state
28+
.get('threads')
29+
.get(`${id}`)
30+
.get('list').size;
31+
return { ...result, [id]: size };
32+
}, {});
33+
return result;
2934
};
3035

3136
const defineContactType = labelId => {

0 commit comments

Comments
 (0)