Update StoryViewer, preload media

This commit is contained in:
Daniel Supernault 2020-03-14 13:12:54 -06:00
parent 664fd2724c
commit 336571d05a
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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;
});
} }
} }
} }