]>
git.r.bdr.sh - rbdr/dasein/blob - app/components/posts.js
d0e03387d9f207f5885d58f395970d87bd3c4229
1 import Axios
from 'axios';
3 import AuthService
from '../services/auth';
5 import PostFormComponent
from './post_form';
6 import PostComponent
from './post';
7 import DatetimeFilter
from '../filters/datetime';
8 import UsertimeFilter
from '../filters/usertime';
12 internals
.kPostsRoute
= '/api/posts';
13 internals
.kPollFrequency
= 5000;
15 export default internals
.PostsComponent
= Vue
.component('posts', {
16 template: '<div v-if="authService.authenticated" class="posts-container">' +
17 '<post-form v-on:post-submitted="addPost"></post-form>' +
19 '<p v-show="message" class="posts-error">{{message}}</p>' +
20 '<post v-for="post in posts" v-bind:post="post" :key="post.uuid"></post>' +
27 authService: new AuthService(),
38 Authorization: `Bearer ${this.authService.token}`
40 url: internals
.kPostsRoute
41 }).then((response
) => {
43 this.posts
= response
.data
;
44 if (!this._isBeingDestroyed
) {
45 setTimeout(this.fetchPosts
.bind(this), internals
.kPollFrequency
);
49 console
.error(err
.stack
);
50 this.message
= 'Error while loading the posts...';
56 this.posts
.unshift(post
);
61 postForm: PostFormComponent
,
63 datetime: DatetimeFilter
,
64 usertime: UsertimeFilter
69 if (!this.authService
.authenticated
) {
70 return this.$router
.push('/login');