Fix firstDay group calculation
parent
d8cd4f17e0
commit
f4c1473c3b
|
@ -30,18 +30,23 @@ var MessageList = React.createClass({
|
|||
{
|
||||
return { firstDayTop: 0, firstDay: this.props.groups && this.props.groups[0] && this.props.groups[0].name || '', groups: this.props.groups||[] /*FIXME*/ };
|
||||
},
|
||||
changeFirstDay: function(ev)
|
||||
componentWillReceiveProps: function(nextProps)
|
||||
{
|
||||
if (!this.state.groups.length)
|
||||
this.setFirstDayFromProps(nextProps);
|
||||
},
|
||||
setFirstDayFromProps: function(props)
|
||||
{
|
||||
var groups = props.groups;
|
||||
if (!groups.length)
|
||||
return;
|
||||
var scrollTop = ev.target.scrollTop, scrollSize = ev.target.offsetHeight - this.getScrollPaddingTop();
|
||||
var scrollTop = this.refs.scroll.scrollTop, scrollSize = this.refs.scroll.offsetHeight - this.getScrollPaddingTop();
|
||||
var top = 0, p, firstVisibleGrp, firstVisible, lastVisibleGrp, lastVisible;
|
||||
var itemH = (this.props.layout == 'message-on-right' ? 60 : 30);
|
||||
var i;
|
||||
for (i = 0; i < this.state.groups.length; i++)
|
||||
for (i = 0; i < groups.length; i++)
|
||||
{
|
||||
p = top;
|
||||
top += (i > 0 ? 30 : 0) + itemH*this.state.groups[i].messageCount;
|
||||
top += (i > 0 ? 30 : 0) + itemH*groups[i].messageCount;
|
||||
if (firstVisibleGrp === undefined && scrollTop < top)
|
||||
{
|
||||
firstVisibleGrp = i;
|
||||
|
@ -57,26 +62,30 @@ var MessageList = React.createClass({
|
|||
lastVisible = 0;
|
||||
else
|
||||
lastVisible = Math.floor((scrollTop+scrollSize - p - (i > 0 ? 30 : 0))/itemH);
|
||||
if (lastVisible >= this.state.groups[i].messageCount)
|
||||
lastVisible = this.state.groups[i].messageCount-1;
|
||||
if (lastVisible >= groups[i].messageCount)
|
||||
lastVisible = groups[i].messageCount-1;
|
||||
}
|
||||
if (firstVisibleGrp !== undefined && lastVisibleGrp !== undefined)
|
||||
break;
|
||||
}
|
||||
if (lastVisibleGrp === undefined)
|
||||
{
|
||||
lastVisibleGrp = this.state.groups.length-1;
|
||||
lastVisible = this.state.groups[lastVisibleGrp].messageCount-1;
|
||||
lastVisibleGrp = groups.length-1;
|
||||
lastVisible = groups[lastVisibleGrp].messageCount-1;
|
||||
}
|
||||
this.setState({
|
||||
firstDayTop: scrollTop,
|
||||
firstDay: this.state.groups[firstVisibleGrp].name,
|
||||
firstDay: groups[firstVisibleGrp].name,
|
||||
firstGrp: firstVisibleGrp,
|
||||
firstMsg: firstVisible,
|
||||
lastGrp: lastVisibleGrp,
|
||||
lastMsg: lastVisible
|
||||
});
|
||||
},
|
||||
changeFirstDay: function(ev)
|
||||
{
|
||||
this.setFirstDayFromProps(this.props);
|
||||
},
|
||||
deleteSelected: function()
|
||||
{
|
||||
|
||||
|
@ -84,13 +93,13 @@ var MessageList = React.createClass({
|
|||
onSelectCurrent: function(index)
|
||||
{
|
||||
var total = 0, p;
|
||||
for (var i = 0; i < this.state.groups.length; i++)
|
||||
for (var i = 0; i < this.props.groups.length; i++)
|
||||
{
|
||||
p = total;
|
||||
total += (i > 0 ? 1 : 0)+this.state.groups[i].messageCount;
|
||||
total += (i > 0 ? 1 : 0)+this.props.groups[i].messageCount;
|
||||
if (index < total)
|
||||
{
|
||||
Store.set('msg', this.state.groups[i].messages[index-p-(i > 0 ? 1 : 0)]);
|
||||
Store.set('msg', this.props.groups[i].messages[index-p-(i > 0 ? 1 : 0)]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -98,9 +107,9 @@ var MessageList = React.createClass({
|
|||
getTotalItems: function()
|
||||
{
|
||||
var total = -1; // do not count first-day as item
|
||||
for (var i = 0; i < this.state.groups.length; i++)
|
||||
for (var i = 0; i < this.props.groups.length; i++)
|
||||
{
|
||||
total += 1+this.state.groups[i].messageCount;
|
||||
total += 1+this.props.groups[i].messageCount;
|
||||
}
|
||||
return total;
|
||||
},
|
||||
|
@ -110,24 +119,18 @@ var MessageList = React.createClass({
|
|||
},
|
||||
getItemOffset: function(index)
|
||||
{
|
||||
/*var c, gmin = 0, gmax = this.state.groups.length;
|
||||
while (gmin != gmax-1)
|
||||
{
|
||||
c = Math.floor((gmax+gmin)/2);
|
||||
if (this.state.groups[c]
|
||||
}*/
|
||||
var n = 0, top = this.refs.title.offsetHeight, p;
|
||||
for (var i = 0; i < this.state.groups.length; i++)
|
||||
for (var i = 0; i < this.props.groups.length; i++)
|
||||
{
|
||||
p = n;
|
||||
n += (i > 0 ? 1 : 0)+this.state.groups[i].messageCount;
|
||||
n += (i > 0 ? 1 : 0)+this.props.groups[i].messageCount;
|
||||
if (index < n)
|
||||
{
|
||||
if (index > p)
|
||||
top += (i > 0 ? 30 : 0) + (this.props.layout == 'message-on-right' ? 60 : 30)*(index-p-1);
|
||||
break;
|
||||
}
|
||||
top += (i > 0 ? 30 : 0) + (this.props.layout == 'message-on-right' ? 60 : 30)*this.state.groups[i].messageCount;
|
||||
top += (i > 0 ? 30 : 0) + (this.props.layout == 'message-on-right' ? 60 : 30)*this.props.groups[i].messageCount;
|
||||
}
|
||||
return [ top, (this.props.layout == 'message-on-right' && (index == 0 || index != p) ? 60 : 30) ];
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue