Merge branch 'feat/ui-0.7.0' into 'test'

Feat/ui 0.7.0

See merge request opensource/answer!349
This commit is contained in:
Ren Yubin 2022-12-16 07:18:15 +00:00
commit dad0b7f888
7 changed files with 1194 additions and 85 deletions

View File

@ -755,6 +755,7 @@ ui:
write_answer: write_answer:
title: Your Answer title: Your Answer
btn_name: Post your answer btn_name: Post your answer
add_another_answer: Add another answer
confirm_title: Continue to answer confirm_title: Continue to answer
continue: Continue continue: Continue
confirm_info: >- confirm_info: >-

View File

@ -50,6 +50,7 @@
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^13.3.0", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"@types/color": "^3.0.3",
"@types/jest": "^27.5.2", "@types/jest": "^27.5.2",
"@types/lodash": "^4.14.184", "@types/lodash": "^4.14.184",
"@types/marked": "^4.0.6", "@types/marked": "^4.0.6",

File diff suppressed because it is too large Load Diff

View File

@ -169,7 +169,7 @@
} }
} }
.content-wrap { .content-wrap {
height: 270px; height: 264px;
} }
.CodeMirror { .CodeMirror {

View File

@ -1,7 +1,9 @@
import { FC, useRef, useEffect, memo } from 'react'; import { FC, useRef, useEffect, memo } from 'react';
import { FormControl, FormControlProps } from 'react-bootstrap'; import { FormControl, FormControlProps } from 'react-bootstrap';
const TextArea: FC<FormControlProps> = ({ value, onChange, size }) => { const TextArea: FC<
FormControlProps & { rows?: number; autoFocus?: boolean }
> = ({ value, onChange, size, rows = 1, autoFocus = true, ...rest }) => {
const ref = useRef<HTMLTextAreaElement>(null); const ref = useRef<HTMLTextAreaElement>(null);
const autoGrow = () => { const autoGrow = () => {
@ -21,13 +23,14 @@ const TextArea: FC<FormControlProps> = ({ value, onChange, size }) => {
<FormControl <FormControl
as="textarea" as="textarea"
className="resize-none font-monospace" className="resize-none font-monospace"
rows={1} rows={rows}
size={size} size={size}
value={value} value={value}
onChange={onChange} onChange={onChange}
autoFocus autoFocus={autoFocus}
ref={ref} ref={ref}
onInput={autoGrow} onInput={autoGrow}
{...rest}
/> />
); );
}; };

View File

@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import { marked } from 'marked'; import { marked } from 'marked';
import classNames from 'classnames'; import classNames from 'classnames';
import { Editor, Modal } from '@/components'; import { Editor, Modal, TextArea } from '@/components';
import { FormDataType } from '@/common/interface'; import { FormDataType } from '@/common/interface';
import { postAnswer } from '@/services'; import { postAnswer } from '@/services';
@ -81,10 +81,13 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {
handleSubmit(); handleSubmit();
}; };
const handleFocusForTextArea = () => {
setShowEditor(true);
};
return ( return (
<Form noValidate className="mt-4"> <Form noValidate className="mt-4">
{showEditor && ( {(!data.answered || showEditor) && (
<Form.Group className="mb-3"> <Form.Group className="mb-3">
<Form.Label> <Form.Label>
<h5>{t('title')}</h5> <h5>{t('title')}</h5>
@ -93,6 +96,17 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {
isInvalid={formData.content.isInvalid} isInvalid={formData.content.isInvalid}
className="d-none" className="d-none"
/> />
{!showEditor && !data.answered && (
<div className="d-flex">
<TextArea
className="w-100"
rows={12}
autoFocus={false}
onFocus={handleFocusForTextArea}
/>
</div>
)}
{showEditor && (
<Editor <Editor
className={classNames( className={classNames(
'form-control p-0', 'form-control p-0',
@ -115,6 +129,7 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {
setForceType(''); setForceType('');
}} }}
/> />
)}
<Form.Control.Feedback type="invalid"> <Form.Control.Feedback type="invalid">
{formData.content.errorMsg} {formData.content.errorMsg}
@ -122,7 +137,11 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {
</Form.Group> </Form.Group>
)} )}
{data.answered && !showEditor ? (
<Button onClick={clickBtn}>{t('add_another_answer')}</Button>
) : (
<Button onClick={clickBtn}>{t('btn_name')}</Button> <Button onClick={clickBtn}>{t('btn_name')}</Button>
)}
</Form> </Form>
); );
}; };

View File

@ -128,6 +128,13 @@ const Index = () => {
count: answers.count + 1, count: answers.count + 1,
list: [...answers.list, obj], list: [...answers.list, obj],
}); });
if (question) {
setQuestion({
...question,
answered: true,
});
}
}; };
useEffect(() => { useEffect(() => {