From 2584e6a379565a47be555c8958c6187ab4fc74f3 Mon Sep 17 00:00:00 2001 From: Mitchell Gerber Date: Sun, 14 Jan 2018 14:54:08 -0600 Subject: [PATCH] client - wip new topic --- client/app/components/editor/editor.scss | 47 ++++++++++ client/app/components/editor/editor.tsx | 88 +++++++++++++++++++ client/app/components/index.ts | 1 + .../components/login-button/login-button.tsx | 9 +- client/app/pages/forum/forum.tsx | 36 +++++++- client/app/pages/thread/thread.scss | 3 + client/app/pages/thread/thread.tsx | 18 ++-- client/app/scss/style.scss | 21 ++++- client/app/util/index.ts | 1 + client/app/util/oauth/oauth.ts | 13 +++ client/package.json | 2 + client/yarn.lock | 8 ++ .../20180102015706_create_thread.exs | 2 +- .../20180103040352_create_reply.exs | 2 +- 14 files changed, 227 insertions(+), 24 deletions(-) create mode 100644 client/app/components/editor/editor.scss create mode 100644 client/app/components/editor/editor.tsx create mode 100644 client/app/util/index.ts create mode 100644 client/app/util/oauth/oauth.ts diff --git a/client/app/components/editor/editor.scss b/client/app/components/editor/editor.scss new file mode 100644 index 0000000..ec2992e --- /dev/null +++ b/client/app/components/editor/editor.scss @@ -0,0 +1,47 @@ +.editor-container { + z-index: 1; + top: 0; + left: 0; + height: calc(100% - 96px); + width: 100%; + position: fixed; + background-color: rgba(0, 0, 0, .5); + padding-top: 50px; +} + +.editor { + height: 80%; + display: flex; + flex-direction: column; + padding-bottom: 40px; + + &__title { + height: 25px; + margin-bottom: 20px; + } + + &__text-area { + min-height: 100px; + resize: none; + margin-bottom: 20px; + overflow-wrap: break-word; + } + + &__preview { + min-height: 100px; + background-color: #161616; + border-radius: 2px; + padding: 5px 10px; + overflow-y: auto; + overflow-wrap: break-word; + } + + &__submit { + padding: 20px 0; + } + + &__error-message { + margin-left: 10px; + color: red; + } +} diff --git a/client/app/components/editor/editor.tsx b/client/app/components/editor/editor.tsx new file mode 100644 index 0000000..c5a6af5 --- /dev/null +++ b/client/app/components/editor/editor.tsx @@ -0,0 +1,88 @@ +import React from 'react'; +import marked from 'marked'; +import axios from '../../axios/axios'; +import { ContentContainer } from '../content-container/content-container'; +import './editor.scss'; + +interface Props { + categoryId: string; + onClose: (cancel: boolean) => any; +} + +interface State { + title: string; + content: string; + contentPreview: string; + characterCount: number; + errorMessage?: string; +} + +export class Editor extends React.Component { + constructor(props: any) { + super(props); + this.state = { + title: '', + content: '', + contentPreview: '', + characterCount: 0, + }; + } + + onContentChange(event: any) { + this.setState({ + content: event.target.value, + contentPreview: marked(event.target.value, { sanitize: true }), + characterCount: event.target.value.length, + }); + } + + onSubmit() { + + const { title, content } = this.state; + + if (title === '' || content === '') { + this.setState({ errorMessage: 'One of your inputs is blank.' }); + return; + } + + const data = { + content, + title, + category_id: this.props.categoryId, + }; + + this.newThread(data); + } + + async newThread(data: any) { + try { + await axios.post('/api/thread', data); + this.props.onClose(false); + } catch (e) { + this.setState({ errorMessage: 'Server error. Please try again later.' }); + } + } + + render() { + + return ( +
+ +

New Topic

+ + this.setState({ title: event.target.value })}/> + +