From 857df18cbfdcbeaef143cb184b6c33bb44d3013f Mon Sep 17 00:00:00 2001 From: Mitchell Gerber Date: Wed, 17 Jan 2018 22:50:22 -0600 Subject: [PATCH] client/server - update reply --- client/app/components/editor/editor.scss | 2 +- client/app/components/editor/editor.tsx | 19 ++++++++++-- client/app/pages/forum/forum.tsx | 4 +-- client/app/pages/thread/thread.tsx | 39 +++++++++++++++++++----- client/index.html | 2 +- lib/myapp/data/reply.ex | 22 ++++++------- 6 files changed, 64 insertions(+), 24 deletions(-) diff --git a/client/app/components/editor/editor.scss b/client/app/components/editor/editor.scss index 9ff1239..8a30dd8 100644 --- a/client/app/components/editor/editor.scss +++ b/client/app/components/editor/editor.scss @@ -25,7 +25,7 @@ margin-bottom: 0; &__title { - height: 25px; + height: 30px; margin-bottom: 10px; } diff --git a/client/app/components/editor/editor.tsx b/client/app/components/editor/editor.tsx index 16c1399..d6002f9 100644 --- a/client/app/components/editor/editor.tsx +++ b/client/app/components/editor/editor.tsx @@ -9,6 +9,7 @@ import './editor.scss'; interface Props { categoryId?: string; onClose: (cancel: boolean) => any; + editingReply?: ReplyModel; quotedReply?: ReplyModel; threadId?: string; } @@ -40,6 +41,11 @@ export class Editor extends React.Component { componentDidMount() { document.body.style.overflow = 'hidden'; + // set content if user is editing a reply + if (this.props.editingReply) { + this.onContentChange({ target: { value: this.props.editingReply.content } }); + } + if (this.titleRef) { this.titleRef.focus(); } else { @@ -84,12 +90,13 @@ export class Editor extends React.Component { const data = { content, + id: get(this.props, 'editingReply.id'), thread_id: this.props.threadId, quote_id: get(this.props, 'quotedReply.id') || undefined, }; try { - await axios.post('/api/reply', data); + this.props.editingReply ? await axios.put('/api/reply', data) : await axios.post('/api/reply', data); this.props.onClose(false); } catch (e) { this.setState({ errorMessage: 'Server error. Please try again later.' }); @@ -140,17 +147,25 @@ export class Editor extends React.Component { ); } + getEditorTitle(): string { + if (!this.props.threadId) { + return 'New Topic'; + } + return `${this.props.editingReply ? 'Edit' : 'New'} Reply`; + } + render() { return (
this.onSubmit(event)} onReset={() => this.props.onClose(true)}> -

New {this.props.threadId ? 'Reply' : 'Topic'}

+

{this.getEditorTitle()}

{!this.props.threadId && this.renderTopicInput()}