From 405c98113139224eb0f57d771d3ff59e8fe25410 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 7 Jul 2022 09:41:59 +0200 Subject: [PATCH] Moved to modern React syntax for EditForm --- apps/comments-ui/src/components/AddForm.js | 2 +- apps/comments-ui/src/components/Comment.js | 4 +- apps/comments-ui/src/components/EditForm.js | 79 ++++++++------------- 3 files changed, 33 insertions(+), 52 deletions(-) diff --git a/apps/comments-ui/src/components/AddForm.js b/apps/comments-ui/src/components/AddForm.js index 5968048c36..b31aa14201 100644 --- a/apps/comments-ui/src/components/AddForm.js +++ b/apps/comments-ui/src/components/AddForm.js @@ -79,7 +79,7 @@ const AddForm = (props) => { diff --git a/apps/comments-ui/src/components/Comment.js b/apps/comments-ui/src/components/Comment.js index ecea69ea6f..381908cbca 100644 --- a/apps/comments-ui/src/components/Comment.js +++ b/apps/comments-ui/src/components/Comment.js @@ -53,7 +53,7 @@ class Comment extends React.Component { if (this.state.isInEditMode) { return ( - + ); } else { return ( @@ -86,4 +86,4 @@ class Comment extends React.Component { } } -export default Comment; \ No newline at end of file +export default Comment; diff --git a/apps/comments-ui/src/components/EditForm.js b/apps/comments-ui/src/components/EditForm.js index 2f99f68755..185e817085 100644 --- a/apps/comments-ui/src/components/EditForm.js +++ b/apps/comments-ui/src/components/EditForm.js @@ -1,64 +1,45 @@ import {formatRelativeTime} from '../utils/helpers'; -import React from 'react'; -import AppContext from '../AppContext'; +import React, {useState} from 'react'; import Avatar from './Avatar'; -class EditForm extends React.Component { - static contextType = AppContext; +const EditForm = (props) => { + // todo: we need to convert the HTML back to an editable state instead of putting it into the textarea + const [message, setMessage] = useState(props.comment.html); - constructor(props) { - super(props); - this.state = { - message: props.value.__html - }; - - this.submitForm = this.submitForm.bind(this); - this.handleChange = this.handleChange.bind(this); - } - - getHTML() { - const text = this.state.message; - - // Convert newlines to
for now (until we add a real editor) - return text.replace('\n', '
'); - } - - async submitForm(event) { + const submitForm = async (event) => { event.preventDefault(); return false; - } + }; - handleChange(event) { - this.setState({message: event.target.value}); - } + const handleChange = (event) => { + setMessage(event.target.value); + }; - render() { - const comment = this.props.comment; + const comment = props.comment; - return ( -
-
-
- -
-

{comment.member.name}

-
{formatRelativeTime(comment.created_at)}
-
+ return ( + +
+
+ +
+

{comment.member.name}

+
{formatRelativeTime(comment.created_at)}
-
-
-