]>
git.r.bdr.sh - rbdr/dasein/blob - app/components/posts.js
c41707fc7e71b8e3963bb807b50994af5ca6c8d9
1 import Axios
from 'axios';
3 import AuthService
from '../services/auth';
5 import PostFormComponent
from './post_form';
6 import DatetimeFilter
from '../filters/datetime';
7 import UsertimeFilter
from '../filters/usertime';
11 internals
.kPostsRoute
= '/api/posts';
13 export default internals
.PostsComponent
= Vue
.component('posts', {
14 template: '<div class="posts-container">' +
15 '<post-form v-on:post-submitted="addPost"></post-form>' +
17 '<p v-show="message" class="posts-error">{{message}}</p>' +
18 '<article class="post" v-for="post in posts">' +
19 '<aside class="post-meta">' +
20 '<img :src="post.userImage" v-bind:alt="\'Avatar for @\' + post.userId">' +
21 '<a v-bind:href="\'https://twitter.com/\' + post.userId">{{post.userName}}</a> said on ' +
22 '<time v-bind:datetime="post.timestamp | datetime">{{post.timestamp | usertime}}</time>' +
24 '<div class="post-content">{{post.content}}</div>' +
32 authService: new AuthService(),
43 Authorization: `Bearer ${this.authService.token}`
45 url: internals
.kPostsRoute
46 }).then((response
) => {
48 this.posts
= response
.data
;
51 console
.err(err
.stack
);
52 this.message
= 'Error while loading the posts...';
58 this.posts
.unshift(post
);
63 postForm: PostFormComponent
,
64 datetime: DatetimeFilter
,
65 usertime: UsertimeFilter
68 mounted: function mounted() {
70 if (!this.authService
.authenticated
) {
71 return this.$router
.push('/login');
74 return this.fetchPosts();