From c521ccbc2ebf2d4d67889a28733d07eab4b8fa7b Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Tue, 27 Aug 2024 18:46:42 +0200 Subject: [PATCH] feat(markdown): when the user is publishing a comment, automatically format it to follow markdown rules --- src/components/edit-menu/edit-menu.tsx | 12 +++++++----- src/components/markdown/markdown.tsx | 18 ++---------------- src/components/post-form/post-form.tsx | 17 +++++++---------- src/components/reply-modal/reply-modal.tsx | 6 ++++-- src/lib/utils/post-utils.ts | 11 +++++++++++ 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/components/edit-menu/edit-menu.tsx b/src/components/edit-menu/edit-menu.tsx index 2837a30c..236eb07f 100644 --- a/src/components/edit-menu/edit-menu.tsx +++ b/src/components/edit-menu/edit-menu.tsx @@ -4,6 +4,7 @@ import { autoUpdate, flip, FloatingFocusManager, offset, shift, useClick, useDis import { Comment, PublishCommentEditOptions, usePublishCommentEdit } from '@plebbit/plebbit-react-hooks'; import styles from './edit-menu.module.css'; import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-utils'; +import { formatMarkdown } from '../../lib/utils/post-utils'; import useChallengesStore from '../../stores/use-challenges-store'; import _ from 'lodash'; import useIsMobile from '../../hooks/use-is-mobile'; @@ -113,6 +114,11 @@ const EditMenu = ({ isAccountMod, isAccountCommentAuthor, isCommentAuthorMod, po setIsEditMenuOpen(false); }; + const handleContentChange = (e: React.ChangeEvent) => { + const formattedContent = formatMarkdown(e.target.value); + setPublishCommentEditOptions((state) => ({ ...state, content: formattedContent })); + }; + return ( <> @@ -140,11 +146,7 @@ const EditMenu = ({ isAccountMod, isAccountCommentAuthor, isCommentAuthorMod, po {isContentEditorOpen && (
-