aboutsummaryrefslogtreecommitdiff
path: root/app/components/posts.js
diff options
context:
space:
mode:
authorRubén Beltrán del Río <ben@nsovocal.com>2017-01-30 02:47:14 -0600
committerGitHub <noreply@github.com>2017-01-30 02:47:14 -0600
commita6ccda0fbc4df683f9568d85eb22b21684d2a0bd (patch)
tree967e98f2d8bf6718858da1fbc279987208b25e06 /app/components/posts.js
parent287fa13b3e600b2340895a5463a288bf08101bb5 (diff)
Create and Show Posts (#3)
* 📝 Update changelog (retroactive) SORRY * Add JSDoc * Document twitter helper * Add posts handler * Remove cookies, set routes under /api * Update readme for clearer callback instructions * Redirect callback to login with token * Add dasein paw helper * Remove unused hostname * Remove hostname, add expiration to config * Rename expiration ttl * Send TTL to posts handler * Add redis dependency * Add redis config to config file * Add DASEIN_REDIS_HOST to env.dist * Correct redis config structure * Add redis db to compose * Add redis to posts handler * Update dasein paw file * Git add uuid * Add first iteration of post handlers * Ignore docs in linter * Ignore generated assets * Ignore docs and assets * Add frontend dependencies + more koa * Add post creation to backend * Adjust readme to show actual callback route * Add npm build as part of docker process * Configure babel * Update paw * Add webpack config * Add frontend code * List globals
Diffstat (limited to 'app/components/posts.js')
-rw-r--r--app/components/posts.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/app/components/posts.js b/app/components/posts.js
new file mode 100644
index 0000000..c41707f
--- /dev/null
+++ b/app/components/posts.js
@@ -0,0 +1,77 @@
+import Axios from 'axios';
+import Vue from 'vue';
+import AuthService from '../services/auth';
+
+import PostFormComponent from './post_form';
+import DatetimeFilter from '../filters/datetime';
+import UsertimeFilter from '../filters/usertime';
+
+const internals = {};
+
+internals.kPostsRoute = '/api/posts';
+
+export default internals.PostsComponent = Vue.component('posts', {
+ template: '<div class="posts-container">' +
+ '<post-form v-on:post-submitted="addPost"></post-form>' +
+ '<h1>Posts.</h1>' +
+ '<p v-show="message" class="posts-error">{{message}}</p>' +
+ '<article class="post" v-for="post in posts">' +
+ '<aside class="post-meta">' +
+ '<img :src="post.userImage" v-bind:alt="\'Avatar for @\' + post.userId">' +
+ '<a v-bind:href="\'https://twitter.com/\' + post.userId">{{post.userName}}</a> said on ' +
+ '<time v-bind:datetime="post.timestamp | datetime">{{post.timestamp | usertime}}</time>' +
+ '</aside>' +
+ '<div class="post-content">{{post.content}}</div>' +
+ '</article>' +
+ '</div>',
+
+ data() {
+
+ return {
+ message: '',
+ authService: new AuthService(),
+ posts: []
+ };
+ },
+
+ methods: {
+ fetchPosts() {
+
+ return Axios({
+ method: 'get',
+ headers: {
+ Authorization: `Bearer ${this.authService.token}`
+ },
+ url: internals.kPostsRoute
+ }).then((response) => {
+
+ this.posts = response.data;
+ }).catch((err) => {
+
+ console.err(err.stack);
+ this.message = 'Error while loading the posts...';
+ });
+ },
+
+ addPost(post) {
+
+ this.posts.unshift(post);
+ }
+ },
+
+ components: {
+ postForm: PostFormComponent,
+ datetime: DatetimeFilter,
+ usertime: UsertimeFilter
+ },
+
+ mounted: function mounted() {
+
+ if (!this.authService.authenticated) {
+ return this.$router.push('/login');
+ }
+
+ return this.fetchPosts();
+ }
+});
+