1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-27 18:26:50 +00:00
pixelfed/resources/assets/js/components/StoryViewer.vue

129 lines
2.6 KiB
Vue
Raw Normal View History

2020-01-02 22:13:47 +00:00
<template>
<div class="container">
<div v-if="loading" class="row">
<div class="col-12 mt-5 pt-5">
<div class="text-center">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</div>
<div v-if="stories.length != 0">
<div id="storyContainer" class="d-none m-3"></div>
</div>
</div>
</template>
<script type="text/javascript">
import 'zuck.js/dist/zuck.css';
import 'zuck.js/dist/skins/snapgram.css';
window.Zuck = require('zuck.js');
export default {
props: ['pid'],
data() {
return {
loading: true,
stories: {},
2020-03-14 19:12:54 +00:00
preloadIndex: null
2020-01-02 22:13:47 +00:00
}
},
beforeMount() {
this.fetchStories();
},
methods: {
fetchStories() {
2020-03-14 19:12:54 +00:00
let self = this;
axios.get('/api/stories/v0/profile/' + this.pid)
2020-01-02 22:13:47 +00:00
.then(res => {
2020-03-14 19:12:54 +00:00
self.stories = res.data;
if(res.data.length == 0) {
2020-01-02 22:13:47 +00:00
window.location.href = '/';
return;
}
2020-03-14 19:12:54 +00:00
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) {
2020-01-02 22:13:47 +00:00
window.stories = new Zuck('storyContainer', {
stories: data,
2020-01-07 06:15:37 +00:00
localStorage: false,
2020-01-02 22:13:47 +00:00
callbacks: {
onOpen (storyId, callback) {
document.body.style.overflow = "hidden";
callback()
},
onEnd (storyId, callback) {
axios.post('/i/stories/viewed', {
id: storyId
});
callback();
},
onClose (storyId, callback) {
document.body.style.overflow = "auto";
callback();
window.location.href = '/';
},
}
});
2020-01-07 06:15:37 +00:00
2020-03-14 19:12:54 +00:00
this.loading = false;
2020-01-07 06:15:37 +00:00
// todo: refactor this mess
2020-03-14 19:12:54 +00:00
document.querySelectorAll('#storyContainer .story')[0].click();
}
return;
2020-01-02 22:13:47 +00:00
}
}
}
</script>
<style type="text/css">
#storyContainer .story {
margin-right: 2rem;
width: 100%;
max-width: 64px;
}
.stories.carousel .story > .item-link > .item-preview {
height: 64px;
}
#zuck-modal.with-effects {
width: 100%;
}
.stories.carousel .story > .item-link > .info .name {
font-weight: 600;
font-size: 12px;
}
.stories.carousel .story > .item-link > .info {
}
</style>