@@ -25,33 +25,6 @@ class Thread extends Component {
2525 } ;
2626 }
2727
28- componentWillReceiveProps ( nextProps ) {
29- if ( this . props . thread && ! nextProps . thread ) {
30- this . props . onBackOption ( ) ;
31- } else if ( this . props . thread . unread ) {
32- if (
33- nextProps . emailKeysUnread . length !== this . props . emailKeysUnread . length
34- ) {
35- this . props . onUpdateUnreadEmails (
36- nextProps . emailKeysUnread ,
37- nextProps . thread . threadId
38- ) ;
39- }
40- }
41- if (
42- this . props . emails . length === 0 &&
43- nextProps . emails . length > this . props . emails . length
44- ) {
45- const groupedIndex =
46- nextProps . indexFirstUnread < 0
47- ? nextProps . emails . length - 1
48- : nextProps . indexFirstUnread ;
49- this . setState ( {
50- groupedIndex : groupedIndex || 0
51- } ) ;
52- }
53- }
54-
5528 render ( ) {
5629 return (
5730 < div className = "thread-container" >
@@ -84,7 +57,9 @@ class Thread extends Component {
8457 />
8558 </ div >
8659 </ div >
87- < div className = "cptx-thread-emails" > { this . renderEmails ( ) } </ div >
60+ < div className = "cptx-thread-emails" ref = { e => ( this . scroll = e ) } >
61+ { this . renderEmails ( ) }
62+ </ div >
8863 </ div >
8964 { this . renderTooltipForEmail ( ) }
9065 </ div >
@@ -102,6 +77,42 @@ class Thread extends Component {
10277 }
10378 }
10479
80+ componentDidUpdate ( prevProps ) {
81+ if ( ! this . props . thread && prevProps . thread ) {
82+ return this . props . onBackOption ( ) ;
83+ }
84+
85+ if (
86+ this . props . thread . unread &&
87+ prevProps . emailKeysUnread . length !== this . props . emailKeysUnread . length
88+ ) {
89+ this . props . onUpdateUnreadEmails (
90+ this . props . emailKeysUnread ,
91+ this . props . thread . threadId
92+ ) ;
93+ }
94+
95+ if (
96+ prevProps . emails . length === 0 &&
97+ prevProps . emails . length > this . props . emails . length
98+ ) {
99+ const groupedIndex =
100+ this . props . indexFirstUnread < 0
101+ ? this . props . emails . length - 1
102+ : this . props . indexFirstUnread ;
103+ this . setState ( {
104+ groupedIndex : groupedIndex || 0
105+ } ) ;
106+ }
107+
108+ if (
109+ this . props . emails . length > prevProps . emails . length &&
110+ prevProps . emails . length !== 0
111+ ) {
112+ this . setScrollToBottomPosition ( ) ;
113+ }
114+ }
115+
105116 renderEmails = ( ) => {
106117 if ( ! this . props . emails . length ) {
107118 return < EmailLoading /> ;
@@ -177,6 +188,11 @@ class Thread extends Component {
177188 groupedIndex : 0
178189 } ) ;
179190 } ;
191+
192+ setScrollToBottomPosition = ( ) => {
193+ const bottomPosition = this . scroll . scrollHeight - this . scroll . clientHeight ;
194+ this . scroll . scrollTop = bottomPosition ;
195+ } ;
180196}
181197
182198const ExpandView = props => (
0 commit comments