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

166 lines
5.3 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-04-18 02:15:29 +00:00
<div v-if="results.hashtags || results.profiles || results.statuses">
2019-02-27 07:04:53 +00:00
<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">
2019-04-18 02:15:29 +00:00
<label class="custom-control-label text-muted font-weight-light" for="filter1">Show Hashtags</label>
2019-02-27 07:04:53 +00:00
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="filter2" v-model="filters.profiles">
2019-04-18 02:15:29 +00:00
<label class="custom-control-label text-muted font-weight-light" for="filter2">Show Profiles</label>
2019-02-27 07:04:53 +00:00
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="filter3" v-model="filters.statuses">
2019-04-18 02:15:29 +00:00
<label class="custom-control-label text-muted font-weight-light" for="filter3">Show Statuses</label>
2019-02-27 07:04:53 +00:00
</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-08 20:20:31 +00:00
<p class="mb-0 text-center">
2019-08-23 00:25:53 +00:00
<button v-if="profile.entity.follow_request" type="button" class="btn btn-secondary btn-sm py-1 font-weight-bold" disabled>Follow Requested</button>
2019-08-23 03:49:20 +00:00
<button v-if="!profile.entity.follow_request && profile.entity.following" type="button" class="btn btn-secondary btn-sm py-1 font-weight-bold" @click.prevent="followProfile(profile, index)">Unfollow</button>
<button v-if="!profile.entity.follow_request && !profile.entity.following" type="button" class="btn btn-primary btn-sm py-1 font-weight-bold" @click.prevent="followProfile(profile, index)">Follow</button>
2019-04-08 20:20:31 +00:00
</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-07-08 03:17:47 +00:00
<div v-for="(status, index) in results.statuses" class="col-4 p-0 p-sm-2 p-md-3 hashtag-post-square">
<a class="card info-overlay card-md-border-0" :href="status.url">
<div :class="[status.filter ? 'square ' + status.filter : 'square']">
<div class="square-content" :style="'background-image: url('+status.thumb+')'"></div>
2019-04-02 03:27:10 +00:00
</div>
2019-07-08 03:17:47 +00:00
</a>
</div>
2019-02-27 07:04:53 +00:00
</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-18 02:36:14 +00:00
axios.get('/api/search', {
params: {
'q': this.query,
'src': 'metro',
'v': 1
}
}).then(res => {
let results = res.data;
this.results.hashtags = results.hashtags;
this.results.profiles = results.profiles;
this.results.statuses = results.posts;
this.loading = false;
}).catch(err => {
this.loading = false;
// this.networkError = true;
})
2019-02-27 07:04:53 +00:00
},
2019-04-02 03:27:10 +00:00
2019-08-23 03:49:20 +00:00
followProfile(profile, index) {
2019-08-23 00:25:53 +00:00
this.loading = true;
2019-04-08 20:20:31 +00:00
axios.post('/i/follow', {
2019-08-23 00:25:53 +00:00
item: profile.entity.id
2019-04-08 20:20:31 +00:00
}).then(res => {
2019-08-23 03:49:20 +00:00
if(profile.entity.local == true) {
this.fetchSearchResults();
return;
} else {
this.loading = false;
this.results.profiles[index].entity.follow_request = true;
return;
}
2019-06-02 02:18:21 +00:00
}).catch(err => {
if(err.response.data.message) {
swal('Error', err.response.data.message, 'error');
}
2019-04-08 20:20:31 +00:00
});
2019-04-02 03:27:10 +00:00
},
2019-02-27 07:04:53 +00:00
}
2019-02-22 20:51:17 +00:00
}
</script>