Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions moon/apps/web/components/Issues/IssueDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function IssueDetailPage({ id }: { id: string }) {
conversations: [],
title: ''
})

const [editorHasText, setEditorHasText] = useState(false);
const [buttonLoading, setButtonLoading] = useState<{ [key: string]: boolean }>({
comment: false,
close: false,
Expand Down Expand Up @@ -190,7 +190,7 @@ export default function IssueDetailPage({ id }: { id: string }) {
{info && info.status === 'open' && (
<>
<h1>Add a comment</h1>
<RichEditor setEditorState={setEditorState} />
<RichEditor setEditorState={setEditorState} setEditorHasText={setEditorHasText}/>
<Flex gap='small' justify={'flex-end'}>
<Button
// loading={motivation === 'close' ? loadings[3] : undefined}
Expand All @@ -202,7 +202,7 @@ export default function IssueDetailPage({ id }: { id: string }) {
</Button>
<Button
loading={buttonLoading.comment}
disabled={editorState === '' || !login}
disabled={editorState === '' || !login || !editorHasText}
onClick={() => save_comment(editorState)}
>
Comment
Expand Down
6 changes: 3 additions & 3 deletions moon/apps/web/components/Issues/IssueNewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function IssueNewPage() {
const [loadings, setLoadings] = useState<boolean[]>([])
const router = useRouter()
const { mutate: submitNewIssue } = usePostIssueSubmit()

const [editorHasText, setEditorHasText] = useState(false);
const set_to_loading = (index: number) => {
setLoadings((prevLoadings) => {
const newLoadings = [...prevLoadings]
Expand Down Expand Up @@ -74,9 +74,9 @@ export default function IssueNewPage() {
</Space>
<Space direction='vertical' style={{ width: '100%' }}>
<h1>Add a description</h1>
<RichEditor setEditorState={setEditorState} />
<RichEditor setEditorState={setEditorState} setEditorHasText={setEditorHasText}/>
<Flex justify={'flex-end'}>
<Button loading={loadings[3]} onClick={() => submit(editorState)}>
<Button disabled={!editorHasText} loading={loadings[3]} onClick={() => submit(editorState)}>
Submit New Issue
</Button>
</Flex>
Expand Down
14 changes: 13 additions & 1 deletion moon/apps/web/components/MrView/rich-editor/LexicalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ExampleTheme from './ExampleTheme';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
import type { LexicalEditor } from 'lexical';

const LexicalContent = ({ lexicalJson }: { lexicalJson: string }) => {
const editorConfig = {
Expand All @@ -13,7 +14,18 @@ const LexicalContent = ({ lexicalJson }: { lexicalJson: string }) => {
},
theme: ExampleTheme,
editable: false,
editorState: lexicalJson,
editorState: (editor: LexicalEditor) => {
if (lexicalJson) {
try {
const parsedState = editor.parseEditorState(lexicalJson);

editor.setEditorState(parsedState);
} catch (e) {
// eslint-disable-next-line no-console
console.warn('Invalid lexical JSON, loading empty editor state.');
}
}
},
};

const placeholder = 'No description provided.';
Expand Down
10 changes: 8 additions & 2 deletions moon/apps/web/components/MrView/rich-editor/RichEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import ExampleTheme from './ExampleTheme';
import ToolbarPlugin from './plugins/ToolbarPlugin';
// import TreeViewPlugin from './plugins/TreeViewPlugin';

import { $getRoot } from 'lexical';
import './styles.css';
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { useEffect} from 'react';
Expand Down Expand Up @@ -45,14 +45,20 @@ function OnChangePlugin({ onChange }:any) {
}


export default function RichEditor({ setEditorState }:any) {
export default function RichEditor({ setEditorState, setEditorHasText}:any) {

function onChange(editorState:any) {
// Call toJSON on the EditorState object, which produces a serialization safe string
const editorStateJSON = editorState.toJSON();
// However, we still have a JavaScript object, so we need to convert it to an actual string with JSON.stringify

setEditorState(JSON.stringify(editorStateJSON));

editorState.read(() => {
const text = $getRoot().getTextContent();

setEditorHasText(text.trim().length > 0);
});
}

return (
Expand Down
5 changes: 3 additions & 2 deletions moon/apps/web/pages/[org]/mr/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const MRDetailPage:PageWithLayout<any> = () =>{
const { id : tempId, title } = router.query;
const { scope } = useScope()
const [editorState, setEditorState] = useState("");
const [editorHasText, setEditorHasText] = useState(false);
const [login, _setLogin] = useState(true);
const [outputHtml, setOutputHtml] = useState('');

Expand Down Expand Up @@ -143,7 +144,7 @@ const MRDetailPage:PageWithLayout<any> = () =>{
<div className="flex flex-col w-full">
<Timeline items={conv_items}/>
<h1>Add a comment</h1>
<RichEditor setEditorState={setEditorState}/>
<RichEditor setEditorState={setEditorState} setEditorHasText={setEditorHasText}/>
<div className="flex gap-2 justify-end">
{mrDetail && mrDetail.status === "open" &&
<Button
Expand All @@ -168,7 +169,7 @@ const MRDetailPage:PageWithLayout<any> = () =>{
</Button>
}
<Button
disabled={!login}
disabled={!login || !editorHasText}
onClick={() => save_comment()}
aria-label="Comment"
className={cn(buttonClasses)}
Expand Down