Skip to content

Commit 5c9b9a6

Browse files
author
Corentin Mors
committed
Breaking change on documentScroll
Signed-off-by: Corentin Mors <corentin.mors@dashlane.com>
1 parent 69adddb commit 5c9b9a6

4 files changed

Lines changed: 57 additions & 250 deletions

File tree

js/photos.js

Lines changed: 32 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -12842,10 +12842,6 @@ __webpack_require__.r(__webpack_exports__);
1284212842
//
1284312843
//
1284412844
//
12845-
//
12846-
//
12847-
//
12848-
//
1284912845

1285012846

1285112847

@@ -12884,54 +12880,13 @@ var DEFAULT_SCROLLING_RESET_TIME_INTERVAL = 150;
1288412880
default: false
1288512881
}
1288612882
},
12887-
data: function data() {
12888-
return {
12889-
shownFirstRow: 0,
12890-
shownLastRow: this.getRowNumber(this.list.length - 1)
12891-
};
12892-
},
12893-
computed: {
12894-
shownList: function shownList() {
12895-
var _this = this;
12896-
12897-
return this.list.filter(function (item, index) {
12898-
return _this.isVisible(index);
12899-
});
12900-
},
12901-
12902-
/**
12903-
* Calculate the top filler needed padding
12904-
* to compensate for the hidden items
12905-
* @returns {string}
12906-
*/
12907-
topPadding: function topPadding() {
12908-
return "".concat(this.shownFirstRow * 100, "%");
12909-
},
12910-
12911-
/**
12912-
* Calculate the bottom filler needed padding
12913-
* to compensate for the hidden items
12914-
* Because bottomShift indicate the index of the last visible item,
12915-
* we need to calcuta ehow any rows there is to compensate
12916-
* between bottomShift and the end of the list
12917-
* @returns {string}
12918-
*/
12919-
bottomPadding: function bottomPadding() {
12920-
return "".concat((this.lastRow - this.shownLastRow) * 100, "%");
12921-
},
12922-
lastRow: function lastRow() {
12923-
return this.getRowNumber(this.list.length - 1);
12924-
}
12925-
},
1292612883
created: function created() {
12927-
window.addEventListener('resize', this.onDocumentScroll);
1292812884
window.addEventListener('scroll', this.onDocumentScroll);
1292912885
},
1293012886
mounted: function mounted() {
1293112887
this.onDocumentScroll();
1293212888
},
1293312889
beforeDestroy: function beforeDestroy() {
12934-
window.removeEventListener('resize', this.onDocumentScroll);
1293512890
window.removeEventListener('scroll', this.onDocumentScroll);
1293612891
},
1293712892
methods: {
@@ -12943,59 +12898,17 @@ var DEFAULT_SCROLLING_RESET_TIME_INTERVAL = 150;
1294312898
Object(_essentials_request_timeout__WEBPACK_IMPORTED_MODULE_1__["clearRequestTimeout"])(this.debounceOnDocumentScrollRequest);
1294412899
}
1294512900

12946-
this.debounceOnDocumentScrollRequest = Object(_essentials_request_timeout__WEBPACK_IMPORTED_MODULE_1__["requestTimeout"])(this.onDocumentScroll, DEFAULT_SCROLLING_RESET_TIME_INTERVAL //
12947-
);
12901+
this.debounceOnDocumentScrollRequest = Object(_essentials_request_timeout__WEBPACK_IMPORTED_MODULE_1__["requestTimeout"])(this.onDocumentScroll, DEFAULT_SCROLLING_RESET_TIME_INTERVAL);
1294812902
},
1294912903

1295012904
/**
1295112905
* Handle document scroll
12952-
* Detect first visible/hidden to implement virtual scrolling
1295312906
*/
1295412907
onDocumentScroll: function onDocumentScroll() {
12955-
// get the row height
12956-
var gridContainer = this.$refs.grid.$el;
12957-
var gridStyles = getComputedStyle(gridContainer);
12958-
var rowHeight = parseFloat(gridStyles.gridTemplateColumns.split(' ')[0], 10); // scrolled content
12959-
// rounding up to tens to make sure we only detect changes by steps of 10px
12960-
12961-
var scrolled = this.roundToTen(window.pageYOffset - this.gridConfig.marginTop); // adding one above and one under to have a trigger area of one row
12962-
12963-
var shownFirstRow = Math.floor(scrolled / (rowHeight + this.gridConfig.gap)) - 1;
12964-
var shownLastRow = Math.ceil(window.innerHeight / rowHeight) + shownFirstRow + 1;
12965-
this.shownFirstRow = Math.max(shownFirstRow, 0); // the first shown row cannot be negative
12966-
12967-
this.shownLastRow = Math.min(shownLastRow, this.lastRow); // the last shown row cannot be lower than the last row
12968-
12969-
if (this.shownLastRow >= this.lastRow) {
12908+
if (window.innerHeight + window.pageYOffset >= document.getElementById('timeline').offsetHeight - 256) {
1297012909
this.$emit('bottomReached');
1297112910
}
1297212911
},
12973-
isVisible: function isVisible(index) {
12974-
var row = this.getRowNumber(index);
12975-
return row >= this.shownFirstRow && row < this.shownLastRow + 1;
12976-
},
12977-
12978-
/**
12979-
* Return the row number of the provided index
12980-
*
12981-
* @param {number} index the index
12982-
* @returns {number}
12983-
*/
12984-
getRowNumber: function getRowNumber(index) {
12985-
// in case the grid config is not here yet, let's
12986-
var count = this.gridConfig ? this.gridConfig.count : this.list.length;
12987-
return Math.floor(index / count);
12988-
},
12989-
12990-
/**
12991-
* Round the provided number to a tens of its value
12992-
*
12993-
* @param {number} number the number to round
12994-
* @returns {number}
12995-
*/
12996-
roundToTen: function roundToTen(number) {
12997-
return Math.floor(number / 10) * 10;
12998-
},
1299912912
getFormatedDate: function getFormatedDate(string, format) {
1300012913
return moment__WEBPACK_IMPORTED_MODULE_0__(string).format(format);
1300112914
}
@@ -13743,6 +13656,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
1374313656

1374413657

1374513658

13659+
var loadedRowNumber = 5;
1374613660
/* harmony default export */ __webpack_exports__["default"] = ({
1374713661
name: 'Timeline',
1374813662
components: {
@@ -13879,16 +13793,17 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
1387913793
_context3.next = 11;
1388013794
return request(this.onlyFavorites, {
1388113795
page: this.page,
13882-
perPage: this.gridConfig.count * 5 // we load 5 rows,
13796+
perPage: this.gridConfig.count * loadedRowNumber // we load loadedRowNumber rows,
1388313797

1388413798
});
1388513799

1388613800
case 11:
1388713801
files = _context3.sent;
1388813802
this.$store.dispatch('updateTimeline', files);
1388913803
this.$store.dispatch('appendFiles', files); // next time we load this script, we load the next page if the list returned
13804+
// this fails if the last page match exactly "this.gridConfig.count * loadedRowNumber"
1389013805

13891-
if (files.length === this.gridConfig.count * 5) {
13806+
if (files.length === this.gridConfig.count * loadedRowNumber) {
1389213807
this.page++;
1389313808
} else {
1389413809
console.debug('We loaded the last page');
@@ -28239,7 +28154,7 @@ module.exports = exports;
2823928154
var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(/*! ../../node_modules/css-loader/dist/runtime/api.js */ "./node_modules/css-loader/dist/runtime/api.js");
2824028155
exports = ___CSS_LOADER_API_IMPORT___(false);
2824128156
// Module
28242-
exports.push([module.i, ".grid-filler[data-v-178c031e] {\n grid-column-end: -1;\n}\n.grid-loading[data-v-178c031e] {\n grid-column: 1/-1;\n height: 88px;\n}\n.grid-title[data-v-178c031e] {\n grid-column: 1/8;\n padding: 36px 0 12px 0;\n background: #fff;\n margin: 0;\n}\n.grid-title span[data-v-178c031e] {\n font-weight: normal;\n}\n.grid-title.first-title[data-v-178c031e] {\n padding: 0 0 12px 0;\n}\n", ""]);
28157+
exports.push([module.i, ".grid-filler[data-v-178c031e] {\n grid-column-end: -1;\n}\n.grid-loading[data-v-178c031e] {\n grid-column: 1/-1;\n height: 88px;\n}\n.grid-title[data-v-178c031e] {\n grid-column: 1/-1;\n padding: 36px 0 12px 0;\n background: #fff;\n margin: 0;\n}\n.grid-title span[data-v-178c031e] {\n font-weight: normal;\n}\n.grid-title.first-title[data-v-178c031e] {\n padding: 0 0 12px 0;\n}\n", ""]);
2824328158
// Exports
2824428159
module.exports = exports;
2824528160

@@ -76853,40 +76768,26 @@ var render = function() {
7685376768
var _c = _vm._self._c || _h
7685476769
return _c(
7685576770
"Grid",
76856-
{ ref: "grid" },
76771+
{ ref: "grid", attrs: { id: "timeline" } },
7685776772
[
76858-
_c("span", {
76859-
directives: [
76860-
{
76861-
name: "show",
76862-
rawName: "v-show",
76863-
value: _vm.shownFirstRow > 0,
76864-
expression: "shownFirstRow > 0"
76865-
}
76866-
],
76867-
key: "filler-top",
76868-
ref: "filler-top",
76869-
staticClass: "grid-filler grid-filler--top",
76870-
style: { paddingBottom: _vm.topPadding },
76871-
attrs: { role: "none" }
76872-
}),
76873-
_vm._v(" "),
76874-
_vm._l(_vm.shownList, function(item, index) {
76773+
_vm._l(_vm.list, function(item, index) {
7687576774
return [
76775+
index == 0
76776+
? _c("span", {
76777+
key: "filler-top-" + index,
76778+
ref: "filler-top",
76779+
refInFor: true,
76780+
staticClass: "grid-filler grid-filler--top",
76781+
attrs: { role: "none" }
76782+
})
76783+
: _vm._e(),
76784+
_vm._v(" "),
7687676785
index == 0 ||
7687776786
_vm.getFormatedDate(item.lastmod, "MMMM YYYY") !=
76878-
_vm.getFormatedDate(_vm.shownList[index - 1].lastmod, "MMMM YYYY")
76787+
_vm.getFormatedDate(_vm.list[index - 1].lastmod, "MMMM YYYY")
7687976788
? _c(
7688076789
"h2",
7688176790
{
76882-
directives: [
76883-
{
76884-
name: "show",
76885-
rawName: "v-show",
76886-
value: true,
76887-
expression: "true"
76888-
}
76889-
],
7689076791
key: item.lastmod,
7689176792
class: ["grid-title", index == 0 ? "first-title" : ""],
7689276793
attrs: { role: "none" }
@@ -76912,14 +76813,23 @@ var render = function() {
7691276813
ref: "item-" + index,
7691376814
refInFor: true,
7691476815
tag: "component",
76915-
class: "row-" + _vm.getRowNumber(index),
7691676816
attrs: { list: _vm.list }
7691776817
},
7691876818
"component",
7691976819
_vm.props(item),
7692076820
false
7692176821
)
76922-
)
76822+
),
76823+
_vm._v(" "),
76824+
index == _vm.list.length
76825+
? _c("span", {
76826+
key: "filler-bottom-" + index,
76827+
ref: "filler-bottom",
76828+
refInFor: true,
76829+
staticClass: "grid-filler grid-filler--bottom",
76830+
attrs: { role: "none" }
76831+
})
76832+
: _vm._e()
7692376833
]
7692476834
}),
7692576835
_vm._v(" "),
@@ -76929,23 +76839,7 @@ var render = function() {
7692976839
staticClass: "grid-loading icon-loading",
7693076840
attrs: { role: "none" }
7693176841
})
76932-
: _vm._e(),
76933-
_vm._v(" "),
76934-
_c("span", {
76935-
directives: [
76936-
{
76937-
name: "show",
76938-
rawName: "v-show",
76939-
value: _vm.shownLastRow < _vm.lastRow,
76940-
expression: "shownLastRow < lastRow"
76941-
}
76942-
],
76943-
key: "filler-bottom",
76944-
ref: "filler-bottom",
76945-
staticClass: "grid-filler grid-filler--bottom",
76946-
style: { paddingBottom: _vm.bottomPadding },
76947-
attrs: { role: "none" }
76948-
})
76842+
: _vm._e()
7694976843
],
7695076844
2
7695176845
)

js/photos.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)