2022-11-24 14:46:29 +01:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data: function() {
|
|
|
|
return {
|
|
|
|
errormsg: null,
|
|
|
|
loading: false,
|
2022-12-09 22:32:02 +01:00
|
|
|
stream_data: [],
|
|
|
|
data_ended: false,
|
|
|
|
start_idx: 0,
|
|
|
|
limit: 1,
|
2022-11-24 14:46:29 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async refresh() {
|
2022-12-13 01:48:28 +01:00
|
|
|
// this way we are sure that we fill the first page
|
|
|
|
// 450 is a bit more of the max height of a post
|
|
|
|
// todo: may not work in 4k screens :/
|
2022-12-09 22:32:02 +01:00
|
|
|
this.limit = Math.round(window.innerHeight / 450);
|
|
|
|
this.start_idx = 0;
|
|
|
|
this.data_ended = false;
|
|
|
|
this.stream_data = [];
|
|
|
|
this.loadContent();
|
|
|
|
},
|
|
|
|
async loadContent() {
|
2022-11-24 14:46:29 +01:00
|
|
|
this.loading = true;
|
|
|
|
this.errormsg = null;
|
|
|
|
try {
|
2022-12-09 22:32:02 +01:00
|
|
|
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
|
|
|
if (response.data.length == 0) this.data_ended = true;
|
|
|
|
else this.stream_data = this.stream_data.concat(response.data);
|
2022-12-09 03:53:16 +01:00
|
|
|
this.loading = false;
|
2022-11-24 14:46:29 +01:00
|
|
|
} catch (e) {
|
2022-12-13 01:48:28 +01:00
|
|
|
// todo: handle better
|
2022-11-24 14:46:29 +01:00
|
|
|
this.errormsg = e.toString();
|
|
|
|
}
|
|
|
|
},
|
2022-12-09 22:32:02 +01:00
|
|
|
scroll () {
|
|
|
|
window.onscroll = () => {
|
|
|
|
let bottomOfWindow = Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop) + window.innerHeight === document.documentElement.offsetHeight
|
|
|
|
if (bottomOfWindow && !this.data_ended) {
|
|
|
|
this.start_idx += this.limit;
|
|
|
|
this.loadContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-11-24 14:46:29 +01:00
|
|
|
},
|
|
|
|
mounted() {
|
2022-12-09 22:32:02 +01:00
|
|
|
this.scroll();
|
2022-12-13 01:48:28 +01:00
|
|
|
this.refresh();
|
2022-11-24 14:46:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-12-10 01:02:48 +01:00
|
|
|
<div class="mt-4">
|
2022-12-09 03:53:16 +01:00
|
|
|
<div class="container">
|
|
|
|
<div class="row justify-content-md-center">
|
|
|
|
<div class="col-xl-6 col-lg-9">
|
2022-12-10 01:02:48 +01:00
|
|
|
<h3 class="card-title border-bottom mb-4 pb-2 text-center">Your daily WASAStream!</h3>
|
2022-12-09 03:53:16 +01:00
|
|
|
|
|
|
|
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
|
|
|
|
2022-12-10 01:02:48 +01:00
|
|
|
<div v-if="(stream_data.length == 0)" class="alert alert-secondary text-center" role="alert">
|
|
|
|
There's nothing here 😢
|
|
|
|
<br />Why don't you start following somebody? 👻
|
|
|
|
</div>
|
|
|
|
|
2022-12-09 03:53:16 +01:00
|
|
|
<div id="main-content" v-for="item of stream_data">
|
|
|
|
<PostCard :user_id="item.user_id"
|
|
|
|
:photo_id="item.photo_id"
|
|
|
|
:name="item.name"
|
|
|
|
:date="item.date"
|
|
|
|
:comments="item.comments"
|
|
|
|
:likes="item.likes"
|
2022-12-12 18:06:56 +01:00
|
|
|
:liked="item.liked" />
|
2022-12-09 03:53:16 +01:00
|
|
|
</div>
|
|
|
|
|
2022-12-09 22:32:02 +01:00
|
|
|
<div v-if="data_ended" class="alert alert-secondary text-center" role="alert">
|
2022-12-10 01:02:48 +01:00
|
|
|
This is the end of your stream. Hooray! 👻
|
2022-12-09 22:32:02 +01:00
|
|
|
</div>
|
|
|
|
|
2022-12-09 03:53:16 +01:00
|
|
|
<LoadingSpinner :loading="loading" /><br />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-24 14:46:29 +01:00
|
|
|
</div>
|
2022-12-13 01:48:28 +01:00
|
|
|
</template>
|