From a6ccda0fbc4df683f9568d85eb22b21684d2a0bd Mon Sep 17 00:00:00 2001 From: Rubén Beltrán del Río Date: Mon, 30 Jan 2017 02:47:14 -0600 Subject: Create and Show Posts (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📝 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 --- app/components/post_form.js | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/components/post_form.js (limited to 'app/components/post_form.js') diff --git a/app/components/post_form.js b/app/components/post_form.js new file mode 100644 index 0000000..cee17b0 --- /dev/null +++ b/app/components/post_form.js @@ -0,0 +1,57 @@ +import Axios from 'axios'; +import Vue from 'vue'; +import AuthService from '../services/auth'; + +const internals = {}; + +internals.kPostsRoute = '/api/posts'; + +export default internals.PostFormComponent = Vue.component('post-form', { + template: '
' + + '

sup.

' + + '' + + '

{{message}}

' + + '' + + '
', + + data() { + + return { + content: '', + message: '', + submitting: false, + authService: new AuthService() + }; + }, + + methods: { + submit() { + + this.submitting = true; + + return Axios({ + method: 'post', + headers: { + Authorization: `Bearer ${this.authService.token}` + }, + data: { + content: this.content + }, + url: internals.kPostsRoute + }).then((response) => { + + this.$emit('post-submitted', response.data); + this.content = ''; + this.message = ''; + this.submitting = false; + }).catch((err) => { + + console.error(err.stack); + this.submitting = false; + this.message = 'Error while creating the post...'; + }); + } + } +}); + + -- cgit