mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 02:35:48 +03:00
Clarify and simplfiy unpagination logic
This commit is contained in:
parent
94fe9999db
commit
5737994957
2 changed files with 20 additions and 24 deletions
|
@ -333,34 +333,28 @@ module.exports = React.createClass({
|
||||||
if (excessHeight <= 0) {
|
if (excessHeight <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var itemlist = this.refs.itemlist;
|
const tiles = this.refs.itemlist.children;
|
||||||
var tiles = itemlist.children;
|
|
||||||
|
|
||||||
// The scroll token of the first/last tile to be unpaginated
|
// The scroll token of the first/last tile to be unpaginated
|
||||||
let markerScrollToken = null;
|
let markerScrollToken = null;
|
||||||
|
|
||||||
// Subtract clientHeights to simulate the events being unpaginated whilst counting
|
// Subtract heights of tiles to simulate the tiles being unpaginated until the
|
||||||
// the events to be unpaginated.
|
// excess height is less than the height of the next tile to subtract. This
|
||||||
if (backwards) {
|
// prevents excessHeight becoming negative, which could lead to future
|
||||||
// Iterate forwards from start of tiles, subtracting event tile height
|
// pagination.
|
||||||
let i = 0;
|
//
|
||||||
while (i < tiles.length && excessHeight > tiles[i].clientHeight) {
|
// If backwards is true, we unpaginate (remove) tiles from the back (top).
|
||||||
|
let i = backwards ? 0 : tiles.length - 1;
|
||||||
|
while (
|
||||||
|
(backwards ? i < tiles.length : i > 0) && excessHeight > tiles[i].clientHeight
|
||||||
|
) {
|
||||||
|
// Subtract height of tile as if it were unpaginated
|
||||||
excessHeight -= tiles[i].clientHeight;
|
excessHeight -= tiles[i].clientHeight;
|
||||||
|
// The tile may not have a scroll token, so guard it
|
||||||
if (tiles[i].dataset.scrollToken) {
|
if (tiles[i].dataset.scrollToken) {
|
||||||
markerScrollToken = tiles[i].dataset.scrollToken;
|
markerScrollToken = tiles[i].dataset.scrollToken;
|
||||||
}
|
}
|
||||||
i++;
|
i += backwards ? 1 : -1;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Iterate backwards from end of tiles, subtracting event tile height
|
|
||||||
let i = tiles.length - 1;
|
|
||||||
while (i > 0 && excessHeight > tiles[i].clientHeight) {
|
|
||||||
excessHeight -= tiles[i].clientHeight;
|
|
||||||
if (tiles[i].dataset.scrollToken) {
|
|
||||||
markerScrollToken = tiles[i].dataset.scrollToken;
|
|
||||||
}
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (markerScrollToken) {
|
if (markerScrollToken) {
|
||||||
|
|
|
@ -251,10 +251,12 @@ var TimelinePanel = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onMessageListUnfillRequest: function(backwards, scrollToken) {
|
onMessageListUnfillRequest: function(backwards, scrollToken) {
|
||||||
|
// If backwards, unpaginate from the back
|
||||||
let dir = backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS;
|
let dir = backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS;
|
||||||
debuglog("TimelinePanel: unpaginating events in direction", dir);
|
debuglog("TimelinePanel: unpaginating events in direction", dir);
|
||||||
|
|
||||||
// All tiles are inserted by MessagePanel to have a scrollToken === eventId
|
// All tiles are inserted by MessagePanel to have a scrollToken === eventId, and
|
||||||
|
// this particular event should be the first or last to be unpaginated.
|
||||||
let eventId = scrollToken;
|
let eventId = scrollToken;
|
||||||
|
|
||||||
let marker = this.state.events.findIndex(
|
let marker = this.state.events.findIndex(
|
||||||
|
|
Loading…
Reference in a new issue