]>
git.r.bdr.sh - rbdr/dasein/blob - app/components/comments.js
e29cedc3c4affdc2b9910ff5ac8dd307438663ff
1 import Axios
from 'axios';
3 import AuthService
from '../services/auth';
5 import CommentFormComponent
from './comment_form';
6 import CommentComponent
from './comment';
7 import DatetimeFilter
from '../filters/datetime';
8 import UsertimeFilter
from '../filters/usertime';
12 internals
.kPostsRoute
= '/api/posts';
13 internals
.kCommentsRoute
= '/comments';
14 internals
.kPollFrequency
= 2000;
16 export default internals
.CommentsComponent
= Vue
.component('comments', {
17 template: '<div class="comments-container">' +
18 '<p v-show="message" class="comments-error">{{message}}</p>' +
19 '<comment v-for="comment in comments" v-bind:comment="comment" :key="comment.uuid"></comment>' +
20 '<comment-form v-bind:postUuid="postUuid" v-on:comment-submitted="addComment"></comment-form>' +
30 authService: new AuthService(),
38 const route
= `${internals.kPostsRoute}/${this.postUuid}${internals.kCommentsRoute}`;
43 Authorization: `Bearer ${this.authService.token}`
46 }).then((response
) => {
48 this.comments
= response
.data
;
49 if (!this._isBeingDestroyed
) {
50 setTimeout(this.fetchComments
.bind(this), internals
.kPollFrequency
);
54 console
.error(err
.stack
);
55 this.message
= 'Error while loading the comments...';
61 this.comments
.push(comment
);
66 commentForm: CommentFormComponent
,
67 comment: CommentComponent
,
68 datetime: DatetimeFilter
,
69 usertime: UsertimeFilter