Skip to content

Commit

Permalink
Update StoryViewer, preload media
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Mar 14, 2020
1 parent 664fd27 commit 336571d
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions resources/assets/js/components/StoryViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
return {
loading: true,
stories: {},
preloadIndex: null
}
},
Expand All @@ -36,14 +37,43 @@
methods: {
fetchStories() {
let self = this;
axios.get('/api/stories/v0/profile/' + this.pid)
.then(res => {
let data = res.data;
if(data.length == 0) {
self.stories = res.data;
if(res.data.length == 0) {
window.location.href = '/';
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', {
stories: data,
localStorage: false,
Expand All @@ -67,15 +97,12 @@
},
}
});
this.loading = false;
this.loading = false;
// todo: refactor this mess
document.querySelectorAll('#storyContainer .story')[0].click()
})
.catch(err => {
window.location.href = '/';
return;
});
document.querySelectorAll('#storyContainer .story')[0].click();
}
return;
}
}
}
Expand Down

0 comments on commit 336571d

Please sign in to comment.