1
0
Fork 0
forked from mirror/pixelfed
pixelfed/resources/assets/js/components/SearchResults.vue

151 lines
4.5 KiB
Vue
Raw Normal View History

2019-02-22 20:51:17 +00:00
<template>
<div class="container">
2019-02-27 07:04:53 +00:00
<div v-if="loading" class="pt-5 text-center">
<div class="spinner-border" role="status">
<span class="sr-only">Loading</span>
2019-02-27 07:04:53 +00:00
</div>
</div>
<div v-if="networkError" class="pt-5 text-center">
<p class="lead font-weight-lighter">An error occured, results could not be loaded.<br> Please try again later.</p>
</div>
<div v-if="!loading && !networkError" class="mt-5 row">
2019-04-02 03:27:10 +00:00
<div class="col-12 col-md-3 mb-4">
2019-02-27 07:04:53 +00:00
<div>
<p class="font-weight-bold">Filters</p>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="filter1" v-model="filters.hashtags">
<label class="custom-control-label text-muted" for="filter1">Show Hashtags</label>
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="filter2" v-model="filters.profiles">
<label class="custom-control-label text-muted" for="filter2">Show Profiles</label>
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="filter3" v-model="filters.statuses">
<label class="custom-control-label text-muted" for="filter3">Show Statuses</label>
</div>
</div>
</div>
<div class="col-12 col-md-9">
2019-04-02 03:27:10 +00:00
<p class="h5 font-weight-bold">Showing results for <i>{{query}}</i></p>
2019-02-27 07:04:53 +00:00
<hr>
2019-04-02 03:27:10 +00:00
<div v-if="filters.hashtags && results.hashtags" class="row mb-4">
2019-02-27 07:04:53 +00:00
<p class="col-12 font-weight-bold text-muted">Hashtags</p>
2019-04-02 03:27:10 +00:00
<a v-for="(hashtag, index) in results.hashtags" class="col-12 col-md-3 mb-3" style="text-decoration: none;" :href="hashtag.url">
2019-02-27 07:04:53 +00:00
<div class="card card-body text-center">
2019-04-02 03:27:10 +00:00
<p class="lead mb-0 text-truncate text-dark" data-toggle="tooltip" :title="hashtag.value">
2019-02-27 07:04:53 +00:00
#{{hashtag.value}}
</p>
<p class="lead mb-0 small font-weight-bold text-dark">
{{hashtag.count}} posts
</p>
</div>
</a>
</div>
2019-04-02 03:27:10 +00:00
<div v-if="filters.profiles && results.profiles" class="row mb-4">
2019-02-27 07:04:53 +00:00
<p class="col-12 font-weight-bold text-muted">Profiles</p>
2019-04-02 03:27:10 +00:00
<a v-for="(profile, index) in results.profiles" class="col-12 col-md-4 mb-3" style="text-decoration: none;" :href="profile.url">
<div class="card card-body text-center">
<p class="text-center">
<img :src="profile.entity.thumb" width="32px" height="32px" class="rounded-circle box-shadow">
</p>
<p class="font-weight-bold text-truncate text-dark">
2019-02-27 07:04:53 +00:00
{{profile.value}}
</p>
2019-04-02 03:27:10 +00:00
<p class="mb-0 text-center">
<button :class="[profile.entity.following ? 'btn btn-secondary btn-sm py-1 font-weight-bold' : 'btn btn-primary btn-sm py-1 font-weight-bold']" v-on:click="followProfile(profile.entity.id)">
{{profile.entity.following ? 'Unfollow' : 'Follow'}}
</button>
</p>
2019-02-27 07:04:53 +00:00
</div>
</a>
</div>
2019-04-02 03:27:10 +00:00
<div v-if="filters.statuses && results.statuses" class="row mb-4">
2019-02-27 07:04:53 +00:00
<p class="col-12 font-weight-bold text-muted">Statuses</p>
2019-04-02 03:27:10 +00:00
<a v-for="(status, index) in results.statuses" class="col-12 col-md-4 mb-3" style="text-decoration: none;" :href="status.url">
<div class="card">
<img class="card-img-top img-fluid" :src="status.thumb" style="height:180px;">
<div class="card-body text-center ">
<p class="mb-0 small text-truncate font-weight-bold text-muted" v-html="status.value">
</p>
</div>
2019-02-27 07:04:53 +00:00
</div>
</a>
</div>
2019-04-02 03:27:10 +00:00
<div v-if="!results.hashtags && !results.profiles && !results.statuses">
<p class="text-center lead">No results found!</p>
</div>
2019-02-27 07:04:53 +00:00
</div>
</div>
2019-02-22 20:51:17 +00:00
</div>
</template>
<style type="text/css" scoped>
2019-02-22 20:51:17 +00:00
</style>
<script type="text/javascript">
export default {
2019-04-02 03:27:10 +00:00
props: ['query', 'profileId'],
2019-02-27 07:04:53 +00:00
data() {
return {
loading: true,
networkError: false,
results: {
hashtags: [],
profiles: [],
statuses: []
},
filters: {
hashtags: true,
profiles: true,
statuses: true
}
}
},
beforeMount() {
this.fetchSearchResults();
},
mounted() {
2019-04-02 03:48:20 +00:00
$('.search-bar input').val(this.query);
2019-02-27 07:04:53 +00:00
},
updated() {
},
methods: {
fetchSearchResults() {
2019-04-02 03:27:10 +00:00
axios.get('/api/search/' + encodeURI(this.query))
2019-02-27 07:04:53 +00:00
.then(res => {
let results = res.data;
2019-04-02 03:27:10 +00:00
this.results.hashtags = results.hashtags;
this.results.profiles = results.profiles;
this.results.statuses = results.posts;
2019-02-27 07:04:53 +00:00
this.loading = false;
}).catch(err => {
this.loading = false;
2019-04-02 03:27:10 +00:00
// this.networkError = true;
2019-02-27 07:04:53 +00:00
})
},
2019-04-02 03:27:10 +00:00
followProfile(id) {
axios.post('/i/follow', {
item: id
}).then(res => {
window.location.href = window.location.href;
});
},
2019-02-27 07:04:53 +00:00
}
2019-02-22 20:51:17 +00:00
}
</script>