From 5b11cd7c65e6b1c0239a72d06c8b066a2eecff56 Mon Sep 17 00:00:00 2001 From: infiinte-persistence Date: Thu, 21 May 2020 16:53:21 +0800 Subject: [PATCH] Comments: add ability to toggle between simple and markdown editor. --- ui/component/comment/view.jsx | 13 +++++++++++-- ui/component/commentCreate/view.jsx | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ui/component/comment/view.jsx b/ui/component/comment/view.jsx index e8c6153c6..268a3dbf1 100644 --- a/ui/component/comment/view.jsx +++ b/ui/component/comment/view.jsx @@ -12,6 +12,7 @@ import * as ICONS from 'constants/icons'; import { FormField, Form } from 'component/common/form'; import CommentCreate from 'component/commentCreate'; import classnames from 'classnames'; +import usePersistedState from 'effects/use-persisted-state'; type Props = { uri: string, @@ -64,6 +65,8 @@ function Comment(props: Props) { // used for controlling visibility of reply comment component const [isReplying, setReplying] = useState(false); + const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false); + // to debounce subsequent requests const shouldFetch = channel === undefined || @@ -99,7 +102,7 @@ function Comment(props: Props) { } function handleEditMessageChanged(event) { - setCommentValue(event.target.value); + setCommentValue(advancedEditor ? event : event.target.value); } function handleSubmit() { @@ -124,6 +127,10 @@ function Comment(props: Props) { setMouseHover(false); } + function toggleEditorMode() { + setAdvancedEditor(!advancedEditor); + } + return (