pixelfed/resources/assets/js/components/DiscoverComponent.vue

118 lines
3.9 KiB
Vue
Raw Normal View History

<template>
<div class="container">
2019-02-11 04:34:12 +00:00
2019-05-28 05:07:45 +00:00
<section class="d-none d-md-flex mb-md-2 pt-2 discover-bar" style="width:auto; overflow: auto hidden;" v-if="categories.length > 0">
2019-06-03 19:13:51 +00:00
<a v-if="config.ab.loops == true" class="text-decoration-none bg-transparent border border-success rounded d-inline-flex align-items-center justify-content-center mr-3 card-disc" href="/discover/loops">
2019-05-28 05:07:45 +00:00
<p class="text-success lead font-weight-bold mb-0">Loops</p>
2019-02-11 04:34:12 +00:00
</a>
2019-05-28 05:07:45 +00:00
<!-- <a class="text-decoration-none rounded d-inline-flex align-items-center justify-content-center mr-3 box-shadow card-disc" href="/discover/personal" style="background: rgb(255, 95, 109);">
<p class="text-white lead font-weight-bold mb-0">For You</p>
</a> -->
2019-02-11 04:34:12 +00:00
2019-03-05 03:27:27 +00:00
<a v-for="(category, index) in categories" :key="index+'_cat_'" class="bg-dark rounded d-inline-flex align-items-end justify-content-center mr-3 box-shadow card-disc" :href="category.url" :style="'background: linear-gradient(rgba(0, 0, 0, 0.3),rgba(0, 0, 0, 0.3)),url('+category.thumb+');'">
2019-02-11 04:34:12 +00:00
<p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;">{{category.name}}</p>
</a>
</section>
<section class="mb-5 section-explore">
<div class="profile-timeline">
<div class="loader text-center">
<div class="lds-ring"><div></div><div></div><div></div><div></div></div>
</div>
<div class="row d-none">
<div class="col-4 p-0 p-sm-2 p-md-3" v-for="post in posts">
<a class="card info-overlay card-md-border-0" :href="post.url">
2019-06-05 03:45:53 +00:00
<div class="square">
<span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
<span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
<span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
<div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
</div>
</div>
</a>
</div>
</div>
</div>
</section>
<section class="mb-5">
2018-11-27 08:56:22 +00:00
<p class="lead text-center">To view more posts, check the <a href="/" class="font-weight-bold">home</a> or <a href="/timeline/public" class="font-weight-bold">local</a> timelines.</p>
</section>
</div>
</template>
2019-02-11 04:34:12 +00:00
<style type="text/css" scoped>
2019-05-28 05:07:45 +00:00
.discover-bar::-webkit-scrollbar {
display: none;
}
2019-02-11 04:34:12 +00:00
.card-disc {
2019-05-28 05:07:45 +00:00
flex: 0 0 160px;
2019-03-05 03:27:27 +00:00
width:160px;
height:100px;
2019-02-11 04:34:12 +00:00
background-size: cover !important;
}
2019-06-05 03:45:53 +00:00
.post-icon {
color: #fff;
position:relative;
margin-top: 10px;
z-index: 9;
opacity: 0.6;
text-shadow: 3px 3px 16px #272634;
}
2019-02-11 04:34:12 +00:00
</style>
<script type="text/javascript">
export default {
data() {
return {
2019-08-05 05:02:02 +00:00
config: window.App.config,
posts: {},
2019-02-11 04:34:12 +00:00
trending: {},
categories: {},
allCategories: {},
}
},
mounted() {
2018-11-27 08:56:22 +00:00
this.fetchData();
2019-02-11 04:34:12 +00:00
this.fetchCategories();
},
methods: {
2018-11-27 08:56:22 +00:00
followUser(id, event) {
axios.post('/i/follow', {
item: id
}).then(res => {
let el = $(event.target);
el.addClass('btn-outline-secondary').removeClass('btn-primary');
el.text('Unfollow');
}).catch(err => {
2019-06-02 02:18:21 +00:00
if(err.response.data.message) {
swal('Error', err.response.data.message, 'error');
}
2018-11-27 08:56:22 +00:00
});
},
2018-11-27 09:17:27 +00:00
fetchData() {
2018-11-27 09:17:27 +00:00
axios.get('/api/v2/discover/posts')
.then((res) => {
let data = res.data;
this.posts = data.posts;
2018-11-27 09:17:27 +00:00
if(this.posts.length > 1) {
$('.section-explore .loader').hide();
$('.section-explore .row.d-none').removeClass('d-none');
}
});
2019-02-11 04:34:12 +00:00
},
fetchCategories() {
axios.get('/api/v2/discover/categories')
.then(res => {
this.allCategories = res.data;
2019-05-28 05:07:45 +00:00
this.categories = res.data;
2019-02-11 04:34:12 +00:00
});
},
}
}
</script>