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 })}/>