1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-13 13:50:27 +05:30

Use Mixins for global functions.

This commit is contained in:
FireMasterK 2020-11-27 12:16:36 +05:30
parent dfa94f6d7f
commit 8e545dfb27
No known key found for this signature in database
GPG Key ID: 8DFF5DD33E93DB58
5 changed files with 134 additions and 130 deletions

View File

@ -1,104 +1,101 @@
<template> <template>
<div v-if="channel"> <div v-if="channel">
<h1 class="uk-text-center"> <h1 class="uk-text-center">
<img v-bind:src="channel.avatarUrl" />{{ channel.name }} <img v-bind:src="channel.avatarUrl" />{{ channel.name }}
</h1> </h1>
<img <img
v-if="channel.bannerUrl" v-if="channel.bannerUrl"
v-bind:src="channel.bannerUrl" v-bind:src="channel.bannerUrl"
style="width: 100%" style="width: 100%"
/> />
<p v-html="this.channel.description.replaceAll('\n', '<br>')"></p> <p v-html="this.channel.description.replaceAll('\n', '<br>')"></p>
<hr /> <hr />
<div class="uk-grid-xl" uk-grid="parallax: 0"> <div class="uk-grid-xl" uk-grid="parallax: 0">
<div <div
class="uk-width-1-2 uk-width-1-3@m uk-width-1-4@l uk-width-1-5@xl" class="uk-width-1-2 uk-width-1-3@m uk-width-1-4@l uk-width-1-5@xl"
v-bind:key="item.url" v-bind:key="item.url"
v-for="item in this.channel.relatedStreams" v-for="item in this.channel.relatedStreams"
> >
<router-link <router-link
class="uk-link-muted uk-text-justify" class="uk-link-muted uk-text-justify"
v-bind:to="item.url || '/'" v-bind:to="item.url || '/'"
> >
<img style="width: 100%" v-bind:src="item.thumbnail" /> <img style="width: 100%" v-bind:src="item.thumbnail" />
<a>{{ item.title }}</a> <a>{{ item.title }}</a>
</router-link> </router-link>
<br /> <br />
<div> <div>
<b class="uk-text-small uk-align-left"> <b class="uk-text-small uk-align-left">
{{ timeFormat(item.duration) }} {{ timeFormat(item.duration) }}
</b> </b>
<b class="uk-text-small uk-align-right"> <b class="uk-text-small uk-align-right">
<font-awesome-icon icon="eye"></font-awesome-icon> <font-awesome-icon icon="eye"></font-awesome-icon>
{{ item.views }} views {{ item.views }} views
</b> </b>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import Constants from "@/Constants.js"; import Constants from "@/Constants.js";
export default { export default {
data() { data() {
return { return {
channel: null channel: null
}; };
}, },
mounted() { mounted() {
this.getChannelData(); this.getChannelData();
window.addEventListener("scroll", this.handleScroll); window.addEventListener("scroll", this.handleScroll);
}, },
unmounted() { unmounted() {
window.removeEventListener("scroll", this.handleScroll); window.removeEventListener("scroll", this.handleScroll);
}, },
methods: { methods: {
async fetchChannel() { async fetchChannel() {
return await ( return await (
await fetch( await fetch(
Constants.BASE_URL + Constants.BASE_URL +
"/channels/" + "/channels/" +
this.$route.params.channelId this.$route.params.channelId
) )
).json(); ).json();
}, },
async getChannelData() { async getChannelData() {
this.fetchChannel() this.fetchChannel()
.then(data => (this.channel = data)) .then(data => (this.channel = data))
.then(() => (document.title = this.channel.name + " - Piped")); .then(() => (document.title = this.channel.name + " - Piped"));
}, },
timeFormat(d) { handleScroll() {
return require("@/utils/TimeUtils.js").default.timeFormat(d); if (this.loading || !this.channel || !this.channel.nextpage) return;
}, if (
handleScroll() { window.innerHeight + window.scrollY >=
if (this.loading || !this.channel || !this.channel.nextpage) return; document.body.offsetHeight - window.innerHeight
if ( ) {
window.innerHeight + window.scrollY >= this.loading = true;
document.body.offsetHeight - window.innerHeight / 2 fetch(
) { Constants.BASE_URL +
this.loading = true; "/nextpage/channels/" +
fetch( this.$route.params.channelId +
Constants.BASE_URL + "?url=" +
"/nextpage/channels/" + encodeURIComponent(this.channel.nextpage)
this.$route.params.channelId + )
"?url=" + .then(body => body.json())
encodeURIComponent(this.channel.nextpage) .then(json => {
) this.channel.relatedStreams.concat(json.relatedStreams);
.then(body => body.json()) this.channel.nextpage = json.nextpage;
.then(json => { this.loading = false;
this.channel.relatedStreams.concat(json.relatedStreams); json.relatedStreams.map(stream =>
this.channel.nextpage = json.nextpage; this.channel.relatedStreams.push(stream)
this.loading = false; );
json.relatedStreams.map(stream => });
this.channel.relatedStreams.push(stream) }
); }
}); }
} };
} </script>
}
};
</script>

View File

@ -51,9 +51,6 @@ export default {
methods: { methods: {
async fetchTrending() { async fetchTrending() {
return await (await fetch(Constants.BASE_URL + "/trending")).json(); return await (await fetch(Constants.BASE_URL + "/trending")).json();
},
timeFormat(d) {
return require("@/utils/TimeUtils.js").default.timeFormat(d);
} }
} }
}; };

View File

@ -14,13 +14,17 @@
<p class="uk-dark"> <p class="uk-dark">
<font-awesome-icon icon="thumbs-down"></font-awesome-icon> <font-awesome-icon icon="thumbs-down"></font-awesome-icon>
{{ video.likes }} <b>{{ video.likes }}</b>
&nbsp;
<font-awesome-icon icon="thumbs-up"></font-awesome-icon> <font-awesome-icon icon="thumbs-up"></font-awesome-icon>
{{ video.dislikes }} <b>{{ video.dislikes }}</b>
</p> </p>
<p> <p>
<font-awesome-icon icon="eye"></font-awesome-icon> <font-awesome-icon icon="eye"></font-awesome-icon>
{{ video.views }} views <b>{{ video.views }}</b> views
</p>
<p>
Uploaded on <b>{{ video.uploadDate }}</b>
</p> </p>
<p class="uk-light" v-html="video.description"></p> <p class="uk-light" v-html="video.description"></p>
<a v-if="sponsors && sponsors.segments" <a v-if="sponsors && sponsors.segments"

View File

@ -12,7 +12,33 @@ import App from './App.vue'
import './registerServiceWorker' import './registerServiceWorker'
const mixin = {
methods: {
timeFormat: function (duration) {
var pad = function (num, size) {
return ("000" + num).slice(size * -1);
};
var time = parseFloat(duration).toFixed(3),
hours = Math.floor(time / 60 / 60),
minutes = Math.floor(time / 60) % 60,
seconds = Math.floor(time - minutes * 60);
var str = "";
if (hours > 0) str += pad(hours, 2) + ":";
str += pad(minutes, 2) + ":" + pad(seconds, 2);
return str;
}
}
}
const app = createApp(App) const app = createApp(App)
app.use(router) app.use(router)
app.mixin(mixin)
app.component('font-awesome-icon', FontAwesomeIcon) app.component('font-awesome-icon', FontAwesomeIcon)
app.mount('#app') app.mount('#app')

View File

@ -1,20 +0,0 @@
export default {
timeFormat: function (duration) {
var pad = function (num, size) {
return ("000" + num).slice(size * -1);
};
var time = parseFloat(duration).toFixed(3),
hours = Math.floor(time / 60 / 60),
minutes = Math.floor(time / 60) % 60,
seconds = Math.floor(time - minutes * 60);
var str = "";
if (hours > 0) str += pad(hours, 2) + ":";
str += pad(minutes, 2) + ":" + pad(seconds, 2);
return str;
}
}