mirror of
https://github.com/pinry/pinry.git
synced 2025-11-18 10:50:38 +01:00
Feature: hasNext works for pin-loading
This commit is contained in:
committed by
Isaac Bythewood
parent
106c6879e2
commit
dfcd3f64d5
@@ -157,42 +157,56 @@ Vue.component('pin-container', {
|
|||||||
"pins": [],
|
"pins": [],
|
||||||
"heightTable": [],
|
"heightTable": [],
|
||||||
"counter": 0,
|
"counter": 0,
|
||||||
"loading": true,
|
status: {
|
||||||
|
loading: true,
|
||||||
|
hasNext: true,
|
||||||
|
offset: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
template: "#pin-container-template",
|
template: "#pin-container-template",
|
||||||
created: function() {
|
created: function() {
|
||||||
this.heightTable = HeightTable(this.args.blockMargin);
|
this.heightTable = HeightTable(this.args.blockMargin);
|
||||||
this.markAsLoading();
|
this.loadMore();
|
||||||
var self = this;
|
var self = this;
|
||||||
var offset = 0;
|
|
||||||
fetchPins(offset).then(
|
|
||||||
function (res) {
|
|
||||||
self.pins = res.data.results;
|
|
||||||
self.markAsLoaded();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
window.addEventListener("optimizedResize", function() {
|
window.addEventListener("optimizedResize", function() {
|
||||||
self.reflow();
|
self.reflow();
|
||||||
});
|
});
|
||||||
|
self.bindScrollHandler();
|
||||||
},
|
},
|
||||||
mounted: function() {
|
mounted: function() {
|
||||||
this.reflow();
|
this.reflow();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
markAsLoaded: function() {
|
loadMore() {
|
||||||
this.loading = false;
|
var self = this;
|
||||||
|
self.markAsLoading();
|
||||||
|
fetchPins(self.status.offset).then(
|
||||||
|
function (res) {
|
||||||
|
self.pins = self.pins.concat(res.data.results);
|
||||||
|
self.status.offset += res.data.results.length;
|
||||||
|
if (res.data.next === null) {
|
||||||
|
self.markAsLoaded(false);
|
||||||
|
} else {
|
||||||
|
self.markAsLoaded(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
markAsLoaded: function(hasNext) {
|
||||||
|
this.status.hasNext = hasNext;
|
||||||
|
this.status.loading = false;
|
||||||
this.$emit(
|
this.$emit(
|
||||||
"loaded",
|
"loaded",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
markAsLoading: function() {
|
markAsLoading: function() {
|
||||||
this.loading = true;
|
this.status.loading = true;
|
||||||
this.$emit(
|
this.$emit(
|
||||||
"loading",
|
"loading",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
scrollHandler: function () {
|
bindScrollHandler: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
function getDocumentScrollTop() {
|
function getDocumentScrollTop() {
|
||||||
@@ -210,14 +224,13 @@ Vue.component('pin-container', {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
scrollHandler = function() {
|
scrollHandler = function() {
|
||||||
if (self.loading) {
|
if (self.status.loading || !self.status.hasNext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('loading...');
|
|
||||||
var windowPosition = getDocumentScrollTop() + window.innerHeight;
|
var windowPosition = getDocumentScrollTop() + window.innerHeight;
|
||||||
var bottom = getDocumentHeight() - 100;
|
var bottom = getDocumentHeight() - 100;
|
||||||
if(windowPosition > bottom) {
|
if(windowPosition > bottom) {
|
||||||
self.loadMore()
|
self.loadMore();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.addEventListener('scroll', function(e) {
|
window.addEventListener('scroll', function(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user