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

148 lines
5.6 KiB
Vue
Raw Normal View History

2018-11-03 03:08:15 +00:00
<style>
2018-10-17 18:41:54 +00:00
span {
font-size: 14px;
}
.comment-text {
}
2018-11-03 03:08:15 +00:00
.comment-text p {
display: inline;
2018-10-17 18:41:54 +00:00
}
</style>
<template>
<div>
2018-11-03 03:08:15 +00:00
<div class="postCommentsLoader text-center">
2018-10-17 18:41:54 +00:00
<div class="lds-ring"><div></div><div></div><div></div><div></div></div>
</div>
2018-11-03 03:08:15 +00:00
<div class="postCommentsContainer d-none">
2018-11-25 05:36:17 +00:00
<p class="mb-1 text-center load-more-link d-none"><a href="#" class="text-muted" v-on:click="loadMore">Load more comments</a></p>
2018-10-17 18:41:54 +00:00
<div class="comments" data-min-id="0" data-max-id="0">
2018-11-27 08:58:39 +00:00
<p class="mb-1" v-for="(comment, index) in results" :data-id="comment.id" :key="comment.id">
2018-11-19 04:37:47 +00:00
<span class="d-flex justify-content-between align-items-center">
<span class="pr-3" style="overflow: hidden;">
<div class="font-weight-bold pr-1"><bdi><a class="text-dark" :href="comment.account.url" :title="comment.account.username">{{l(comment.account.username)}}</a></bdi>
</div>
2018-11-29 02:27:38 +00:00
<div class="read-more" style="overflow: hidden;" :id="comment.id + '-reply-readmore'">
2018-11-19 04:37:47 +00:00
<span class="comment-text" v-html="comment.content" style="overflow: hidden;"></span>
</div>
2018-11-13 19:46:38 +00:00
</span>
2018-11-25 05:36:17 +00:00
<b-dropdown :id="comment.uri" variant="link" no-caret right class="float-right">
2018-11-13 19:46:38 +00:00
<template slot="button-content">
<i class="fas fa-ellipsis-v text-muted"></i><span class="sr-only">Options</span>
</template>
<b-dropdown-item class="font-weight-bold" v-on:click="reply(comment)">Reply</b-dropdown-item>
<b-dropdown-item class="font-weight-bold" :href="comment.url">Permalink</b-dropdown-item>
2018-12-15 08:16:22 +00:00
<!-- <b-dropdown-item class="font-weight-bold" v-on:click="embed(comment)">Embed</b-dropdown-item> -->
2018-11-13 19:46:38 +00:00
<b-dropdown-item class="font-weight-bold" :href="comment.account.url">Profile</b-dropdown-item>
<b-dropdown-divider></b-dropdown-divider>
<b-dropdown-item class="font-weight-bold" :href="'/i/report?type=post&id='+comment.id">Report</b-dropdown-item>
2018-11-22 20:21:36 +00:00
<b-dropdown-item class="font-weight-bold" v-on:click="deleteComment(comment.id, index)" v-if="comment.account.id == user.id">Delete</b-dropdown-item>
2018-11-13 19:46:38 +00:00
</b-dropdown>
2018-10-17 18:41:54 +00:00
</span>
</p>
</div>
</div>
</div>
</template>
<script>
export default {
2018-11-22 20:21:36 +00:00
props: ['post-id', 'post-username', 'user'],
2018-10-17 18:41:54 +00:00
data() {
return {
2018-11-29 02:27:38 +00:00
results: null,
2018-10-17 18:41:54 +00:00
pagination: {},
min_id: 0,
max_id: 0,
reply_to_profile_id: 0,
}
},
mounted() {
this.fetchData();
},
2018-11-13 19:46:38 +00:00
updated() {
pixelfed.readmore();
},
2018-10-17 18:41:54 +00:00
methods: {
embed(e) {
2018-11-25 05:36:17 +00:00
//pixelfed.embed.build(e);
2018-10-17 18:41:54 +00:00
},
2018-11-22 20:21:36 +00:00
deleteComment(id, i) {
axios.post('/i/delete', {
type: 'comment',
item: id
}).then(res => {
this.results.splice(i, 1);
}).catch(err => {
swal('Something went wrong!', 'Please try again later', 'error');
});
},
2018-11-03 03:08:15 +00:00
l(e) {
let len = e.length;
if(len < 10) { return e; }
return e.substr(0, 10)+'...';
},
2018-10-17 18:41:54 +00:00
reply(e) {
this.reply_to_profile_id = e.account.id;
$('.comment-form input[name=comment]').val('@'+e.account.username+' ');
$('.comment-form input[name=comment]').focus();
},
fetchData() {
let url = '/api/v2/comments/'+this.postUsername+'/status/'+this.postId;
axios.get(url)
.then(response => {
let self = this;
this.results = response.data.data;
this.pagination = response.data.meta.pagination;
2018-11-25 05:36:17 +00:00
if(this.results.length > 0) {
$('.load-more-link').removeClass('d-none');
}
2018-11-03 03:08:15 +00:00
$('.postCommentsLoader').addClass('d-none');
$('.postCommentsContainer').removeClass('d-none');
2018-10-17 18:41:54 +00:00
}).catch(error => {
2018-11-03 03:08:15 +00:00
if(!error.response) {
$('.postCommentsLoader .lds-ring')
.attr('style','width:100%')
.addClass('pt-4 font-weight-bold text-muted')
2018-12-25 21:59:32 +00:00
.text('An error occurred, cannot fetch comments. Please try again later.');
2018-11-03 03:08:15 +00:00
} else {
switch(error.response.status) {
case 401:
$('.postCommentsLoader .lds-ring')
.attr('style','width:100%')
.addClass('pt-4 font-weight-bold text-muted')
.text('Please login to view.');
break;
default:
$('.postCommentsLoader .lds-ring')
.attr('style','width:100%')
.addClass('pt-4 font-weight-bold text-muted')
2018-12-25 21:59:32 +00:00
.text('An error occurred, cannot fetch comments. Please try again later.');
2018-11-03 03:08:15 +00:00
break;
}
}
2018-10-17 18:41:54 +00:00
});
},
loadMore(e) {
e.preventDefault();
if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
$('.load-more-link').addClass('d-none');
return;
}
2018-11-03 03:08:15 +00:00
$('.postCommentsLoader').removeClass('d-none');
2018-10-17 18:41:54 +00:00
let next = this.pagination.links.next;
axios.get(next)
.then(response => {
let self = this;
let res = response.data.data;
2018-11-03 03:08:15 +00:00
$('.postCommentsLoader').addClass('d-none');
2018-10-17 18:41:54 +00:00
for(let i=0; i < res.length; i++) {
this.results.unshift(res[i]);
}
this.pagination = response.data.meta.pagination;
});
}
}
}
</script>