2020-12-09 13:33:29 +00:00
|
|
|
<template>
|
|
|
|
<h1 class="uk-text-center">
|
|
|
|
{{ $route.query.search_query }}
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
<div v-if="results" class="uk-grid-xl" uk-grid="parallax: 0">
|
|
|
|
<div
|
|
|
|
style="background: #0b0e0f"
|
|
|
|
class="uk-width-1-2 uk-width-1-3@s uk-width-1-4@m uk-width-1-5@l uk-width-1-6@xl"
|
|
|
|
v-bind:key="result.url"
|
2020-12-14 07:15:09 +00:00
|
|
|
v-for="result in results.items"
|
2020-12-09 13:33:29 +00:00
|
|
|
>
|
|
|
|
<div class="uk-text-secondary" style="background: #0b0e0f">
|
2021-05-28 19:32:10 +00:00
|
|
|
<router-link class="uk-text-emphasis" v-bind:to="result.url">
|
2021-04-07 11:45:40 +00:00
|
|
|
<img style="width: 100%" v-bind:src="result.thumbnail" loading="lazy" />
|
2021-05-28 19:32:10 +00:00
|
|
|
<p>
|
|
|
|
{{ result.name }} <font-awesome-icon
|
|
|
|
v-if="result.verified"
|
|
|
|
icon="check"
|
|
|
|
></font-awesome-icon>
|
|
|
|
</p>
|
2020-12-09 13:33:29 +00:00
|
|
|
</router-link>
|
2021-05-28 19:32:10 +00:00
|
|
|
<p v-if="result.description">{{ result.description }}</p>
|
|
|
|
<router-link class="uk-link-muted" v-if="result.uploaderUrl" v-bind:to="result.uploaderUrl">
|
|
|
|
<p>
|
|
|
|
{{ result.uploader }} <font-awesome-icon
|
|
|
|
v-if="result.uploaderVerified"
|
|
|
|
icon="check"
|
|
|
|
></font-awesome-icon>
|
|
|
|
</p>
|
2020-12-09 13:33:29 +00:00
|
|
|
</router-link>
|
2021-05-10 18:11:51 +00:00
|
|
|
<b v-if="result.duration" class="uk-text-small uk-align-right uk-text-align-right">
|
|
|
|
{{ timeFormat(result.duration) }}
|
2021-05-06 17:40:32 +00:00
|
|
|
</b>
|
|
|
|
|
2021-05-28 19:32:10 +00:00
|
|
|
<b v-if="result.uploadDate">
|
2021-03-30 14:57:01 +00:00
|
|
|
{{ result.uploadDate }}
|
|
|
|
</b>
|
2021-05-06 17:40:32 +00:00
|
|
|
|
2021-05-28 19:32:10 +00:00
|
|
|
<a v-if="result.uploaderName" class="uk-text-muted">{{ result.uploaderName }}</a>
|
|
|
|
<b v-if="result.videos"><br v-if="result.uploaderName" />{{ result.videos }} Videos</b>
|
|
|
|
|
2021-05-06 17:40:32 +00:00
|
|
|
<br />
|
|
|
|
|
|
|
|
<b v-if="result.views" class="uk-text-small">
|
2020-12-09 13:33:29 +00:00
|
|
|
<font-awesome-icon icon="eye"></font-awesome-icon>
|
|
|
|
{{ result.views }} views
|
|
|
|
</b>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Constants from "@/Constants.js";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-07 11:45:40 +00:00
|
|
|
results: null,
|
2020-12-09 13:33:29 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.updateResults();
|
2020-12-14 07:15:09 +00:00
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
2020-12-09 13:33:29 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2021-01-23 17:00:52 +00:00
|
|
|
"$route.query.search_query": function(q) {
|
|
|
|
if (q) this.updateResults();
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2020-12-09 13:33:29 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async fetchResults() {
|
2021-02-24 09:35:41 +00:00
|
|
|
return await await this.fetchJson(
|
2021-04-07 11:45:40 +00:00
|
|
|
Constants.BASE_URL + "/search?q=" + encodeURIComponent(this.$route.query.search_query),
|
2021-02-24 09:35:41 +00:00
|
|
|
);
|
2020-12-09 13:33:29 +00:00
|
|
|
},
|
|
|
|
async updateResults() {
|
2020-12-14 07:15:09 +00:00
|
|
|
document.title = this.$route.query.search_query + " - Piped";
|
2021-04-07 11:45:40 +00:00
|
|
|
this.results = this.fetchResults().then(json => (this.results = json));
|
2020-12-14 07:15:09 +00:00
|
|
|
},
|
|
|
|
handleScroll() {
|
|
|
|
if (this.loading || !this.results || !this.results.nextpage) return;
|
2021-04-07 11:45:40 +00:00
|
|
|
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
|
2020-12-14 07:15:09 +00:00
|
|
|
this.loading = true;
|
2021-02-24 09:35:41 +00:00
|
|
|
this.fetchJson(
|
2020-12-14 07:15:09 +00:00
|
|
|
Constants.BASE_URL +
|
|
|
|
"/nextpage/search" +
|
|
|
|
"?url=" +
|
|
|
|
encodeURIComponent(this.results.nextpage) +
|
|
|
|
"&id=" +
|
|
|
|
encodeURIComponent(this.results.id) +
|
|
|
|
"&q=" +
|
2021-04-07 11:45:40 +00:00
|
|
|
encodeURIComponent(this.$route.query.search_query),
|
2021-02-24 09:35:41 +00:00
|
|
|
).then(json => {
|
|
|
|
this.results.nextpage = json.nextpage;
|
|
|
|
this.results.id = json.id;
|
|
|
|
this.loading = false;
|
|
|
|
json.items.map(stream => this.results.items.push(stream));
|
|
|
|
});
|
2020-12-14 07:15:09 +00:00
|
|
|
}
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-09 13:33:29 +00:00
|
|
|
};
|
|
|
|
</script>
|