Update PostComponent

This commit is contained in:
Daniel Supernault 2019-02-10 22:31:49 -07:00
parent 4c4f8a7394
commit 276712014b
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 47 additions and 34 deletions

View File

@ -1,10 +1,4 @@
<style scoped> <style scoped>
#l-modal .modal-body,
#s-modal .modal-body {
max-height: 70vh;
overflow-y: scroll;
}
.status-comments, .status-comments,
.reactions, .reactions,
.col-md-4 { .col-md-4 {
@ -21,7 +15,7 @@
</style> </style>
<template> <template>
<div class="postComponent d-none"> <div class="postComponent d-none">
<div class="container px-0 mt-md-4"> <div class="container px-0">
<div class="card card-md-rounded-0 status-container orientation-unknown"> <div class="card card-md-rounded-0 status-container orientation-unknown">
<div class="row px-0 mx-0"> <div class="row px-0 mx-0">
<div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100"> <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
@ -46,8 +40,9 @@
<a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a> <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
</span> </span>
<span class="menu-author d-none"> <span class="menu-author d-none">
<!-- <a class="dropdown-item font-weight-bold" :href="editUrl()">Disable Comments</a> -->
<a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a> <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
<a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a> <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
</span> </span>
</div> </div>
</div> </div>
@ -108,6 +103,8 @@
<a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a> <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
</span> </span>
<span class="menu-author d-none"> <span class="menu-author d-none">
<!-- <a class="dropdown-item font-weight-bold" :href="editUrl()">Mute Comments</a>
<a class="dropdown-item font-weight-bold" :href="editUrl()">Disable Comments</a> -->
<a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a> <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
<a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a> <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
</span> </span>
@ -172,7 +169,7 @@
title="Likes" title="Likes"
body-class="list-group-flush p-0"> body-class="list-group-flush p-0">
<div class="list-group"> <div class="list-group">
<div class="list-group-item border-0" v-for="user in likes"> <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
<div class="media"> <div class="media">
<a :href="user.url"> <a :href="user.url">
<img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px"> <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px">
@ -203,12 +200,13 @@
title="Shares" title="Shares"
body-class="list-group-flush p-0"> body-class="list-group-flush p-0">
<div class="list-group"> <div class="list-group">
<div class="list-group-item border-0" v-for="user in shares"> <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
<div class="media"> <div class="media">
<a :href="user.url"> <a :href="user.url">
<img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px"> <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '\'s avatar'" width="30px">
</a> </a>
<div class="media-body"> <div class="media-body">
<div class="d-inline-block">
<p class="mb-0" style="font-size: 14px"> <p class="mb-0" style="font-size: 14px">
<a :href="user.url" class="font-weight-bold text-dark"> <a :href="user.url" class="font-weight-bold text-dark">
{{user.username}} {{user.username}}
@ -219,6 +217,8 @@
</a> </a>
</p> </p>
</div> </div>
<p class="float-right"><a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a></p>
</div>
</div> </div>
</div> </div>
<infinite-loading @infinite="infiniteSharesHandler" spinner="spiral"> <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
@ -245,9 +245,9 @@ export default {
liked: false, liked: false,
shared: false shared: false
}, },
likes: {}, likes: [],
likesPage: 1, likesPage: 1,
shares: {}, shares: [],
sharesPage: 1, sharesPage: 1,
} }
}, },
@ -267,13 +267,13 @@ export default {
if(this.reactions) { if(this.reactions) {
if(this.reactions.bookmarked == true) { if(this.reactions.bookmarked == true) {
$('.far.fa-bookmark').removeClass('far').addClass('fas text-warning'); $('.postComponent .far.fa-bookmark').removeClass('far').addClass('fas text-warning');
} }
if(this.reactions.shared == true) { if(this.reactions.shared == true) {
$('.far.fa-share-square').addClass('text-primary'); $('.postComponent .far.fa-share-square').addClass('text-primary');
} }
if(this.reactions.liked == true) { if(this.reactions.liked == true) {
$('.far.fa-heart ').removeClass('far text-dark').addClass('fas text-danger'); $('.postComponent .far.fa-heart').removeClass('far text-dark').addClass('fas text-danger');
} }
} }
@ -383,9 +383,9 @@ export default {
page: this.likesPage, page: this.likesPage,
}, },
}).then(({ data }) => { }).then(({ data }) => {
if (data.data.length) { if (data.data.length > 0) {
this.likesPage += 1;
this.likes.push(...data.data); this.likes.push(...data.data);
this.likesPage++;
$state.loaded(); $state.loaded();
} else { } else {
$state.complete(); $state.complete();
@ -399,9 +399,9 @@ export default {
page: this.sharesPage, page: this.sharesPage,
}, },
}).then(({ data }) => { }).then(({ data }) => {
if (data.data.length) { if (data.data.length > 0) {
this.sharesPage += 1;
this.shares.push(...data.data); this.shares.push(...data.data);
this.sharesPage++;
$state.loaded(); $state.loaded();
} else { } else {
$state.complete(); $state.complete();
@ -420,10 +420,17 @@ export default {
this.status.favourites_count = res.data.count; this.status.favourites_count = res.data.count;
if(this.reactions.liked == true) { if(this.reactions.liked == true) {
this.reactions.liked = false; this.reactions.liked = false;
let user = this.user.id;
this.likes = this.likes.filter(function(like) {
return like.id !== user;
});
} else { } else {
this.reactions.liked = true; this.reactions.liked = true;
let user = this.user;
this.likes.push(user);
} }
}).catch(err => { }).catch(err => {
console.error(err);
swal('Error', 'Something went wrong, please try again later.', 'error'); swal('Error', 'Something went wrong, please try again later.', 'error');
}); });
}, },
@ -439,10 +446,17 @@ export default {
this.status.reblogs_count = res.data.count; this.status.reblogs_count = res.data.count;
if(this.reactions.shared == true) { if(this.reactions.shared == true) {
this.reactions.shared = false; this.reactions.shared = false;
let user = this.user.id;
this.shares = this.shares.filter(function(reaction) {
return reaction.id !== user;
});
} else { } else {
this.reactions.shared = true; this.reactions.shared = true;
let user = this.user;
this.shares.push(user);
} }
}).catch(err => { }).catch(err => {
console.error(err);
swal('Error', 'Something went wrong, please try again later.', 'error'); swal('Error', 'Something went wrong, please try again later.', 'error');
}); });
}, },
@ -495,16 +509,15 @@ export default {
}); });
}, },
deletePost() { deletePost(status) {
var result = confirm('Are you sure you want to delete this post?'); var result = confirm('Are you sure you want to delete this post?');
if (result) { if (result) {
if($('body').hasClass('loggedIn') == false) { if($('body').hasClass('loggedIn') == false) {
return; return;
} }
axios.post('/i/delete', { axios.post('/i/delete', {
type: 'status', type: 'status',
item: this.status.id item: status.id
}).then(res => { }).then(res => {
swal('Success', 'You have successfully deleted this post', 'success'); swal('Success', 'You have successfully deleted this post', 'success');
}).catch(err => { }).catch(err => {