mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-29 17:53:16 +00:00
Update StoryViewer, preload media
This commit is contained in:
parent
664fd2724c
commit
336571d05a
1 changed files with 37 additions and 10 deletions
|
@ -27,6 +27,7 @@
|
||||||
return {
|
return {
|
||||||
loading: true,
|
loading: true,
|
||||||
stories: {},
|
stories: {},
|
||||||
|
preloadIndex: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -36,14 +37,43 @@
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
fetchStories() {
|
fetchStories() {
|
||||||
|
let self = this;
|
||||||
axios.get('/api/stories/v0/profile/' + this.pid)
|
axios.get('/api/stories/v0/profile/' + this.pid)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
let data = res.data;
|
self.stories = res.data;
|
||||||
if(data.length == 0) {
|
if(res.data.length == 0) {
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window._storyData = data;
|
self.preloadImages();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
// window.location.href = '/';
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
preloadImages() {
|
||||||
|
let self = this;
|
||||||
|
for (var i = 0; i < this.stories[0].items.length; i++) {
|
||||||
|
var preload = new Image();
|
||||||
|
$(preload).on('load', function() {
|
||||||
|
|
||||||
|
self.preloadIndex = i;
|
||||||
|
if(i == self.stories[0].items.length) {
|
||||||
|
self.loadViewer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
preload.src = self.stories[0].items[i].src;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
loadViewer() {
|
||||||
|
let data = this.stories;
|
||||||
|
|
||||||
|
if(!window.stories) {
|
||||||
window.stories = new Zuck('storyContainer', {
|
window.stories = new Zuck('storyContainer', {
|
||||||
stories: data,
|
stories: data,
|
||||||
localStorage: false,
|
localStorage: false,
|
||||||
|
@ -67,15 +97,12 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.loading = false;
|
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
// todo: refactor this mess
|
// todo: refactor this mess
|
||||||
document.querySelectorAll('#storyContainer .story')[0].click()
|
document.querySelectorAll('#storyContainer .story')[0].click();
|
||||||
})
|
}
|
||||||
.catch(err => {
|
return;
|
||||||
window.location.href = '/';
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue