Update Profile.vue, fix pagination

pull/5916/head
Daniel Supernault 7 months ago
parent c96721dbb4
commit 2ea1078053
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -608,9 +608,9 @@
user: false, user: false,
timeline: [], timeline: [],
timelinePage: 2, timelinePage: 2,
min_id: 0, cursor: undefined,
max_id: 0,
loading: true, loading: true,
canLoadMore: false,
owner: false, owner: false,
layout: 'metro', layout: 'metro',
mode: 'grid', mode: 'grid',
@ -726,21 +726,33 @@
let apiUrl = '/api/pixelfed/v1/accounts/' + this.profileId + '/statuses'; let apiUrl = '/api/pixelfed/v1/accounts/' + this.profileId + '/statuses';
axios.get(apiUrl, { axios.get(apiUrl, {
params: { params: {
limit: 9,
pinned: true,
only_media: true, only_media: true,
min_id: 1,
} }
}) })
.then(res => { .then(res => {
let data = res.data.filter(status => status.media_attachments.length > 0); let data = res.data.filter(status => status.media_attachments.length > 0);
let ids = data.map(status => status.id); let ids = data.map(status => status.id);
this.ids = ids; this.ids = ids;
this.min_id = Math.max(...ids); if(res.headers && res.headers.link) {
this.max_id = Math.min(...ids); const links = parseLinkHeader(res.headers.link);
if(links.prev) {
this.cursor = links.prev.cursor;
this.canLoadMore = true;
} else {
this.cursor = null;
this.canLoadMore = false;
$state.complete();
}
} else {
this.cursor = null;
this.canLoadMore = false;
}
this.modalStatus = _.first(res.data); this.modalStatus = _.first(res.data);
this.timeline = data; this.timeline = data;
this.ownerCheck(); this.ownerCheck();
this.loading = false; this.loading = false;
//this.loadSponsor();
}).catch(err => { }).catch(err => {
swal('Oops, something went wrong', swal('Oops, something went wrong',
'Please release the page.', 'Please release the page.',
@ -757,18 +769,20 @@
}, },
infiniteTimeline($state) { infiniteTimeline($state) {
if(this.loading || this.timeline.length < 9) { if(this.loading || !this.cursor || !this.canLoadMore) {
$state.complete(); // $state.complete();
return; return;
} }
let apiUrl = '/api/pixelfed/v1/accounts/' + this.profileId + '/statuses'; let apiUrl = '/api/pixelfed/v1/accounts/' + this.profileId + '/statuses';
axios.get(apiUrl, { axios.get(apiUrl, {
params: { params: {
limit: 9,
pinned: true,
only_media: true, only_media: true,
max_id: this.max_id cursor: this.cursor,
}, },
}).then(res => { }).then(res => {
if (res.data.length && this.loading == false) { if (res.data.length) {
let data = res.data; let data = res.data;
let self = this; let self = this;
data.forEach(d => { data.forEach(d => {
@ -777,13 +791,20 @@
self.ids.push(d.id); self.ids.push(d.id);
} }
}); });
let max = Math.min(...this.ids); if(res.headers && res.headers.link) {
if(max == this.max_id) { const links = parseLinkHeader(res.headers.link);
if(links.prev) {
this.cursor = links.prev.cursor;
this.canLoadMore = true;
} else {
this.cursor = null;
this.canLoadMore = false;
$state.complete(); $state.complete();
return;
} }
this.min_id = Math.max(...this.ids); } else {
this.max_id = max; this.cursor = null;
this.canLoadMore = false;
}
$state.loaded(); $state.loaded();
this.loading = false; this.loading = false;
} else { } else {

Loading…
Cancel
Save