Merge pull request #563 from answerdev/feat/1.2.0/ui

Feat/1.2.0/UI
This commit is contained in:
dashuai 2023-10-10 11:56:11 +08:00 committed by GitHub
commit 7ca5aa389f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 45 deletions

View File

@ -1,7 +1,6 @@
import { import {
useEffect, useEffect,
useRef, useRef,
useState,
ForwardRefRenderFunction, ForwardRefRenderFunction,
forwardRef, forwardRef,
useImperativeHandle, useImperativeHandle,
@ -74,14 +73,6 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (
autoFocus, autoFocus,
}); });
const [markdown, setMarkdown] = useState<string>(value || '');
useEffect(() => {
if (value !== markdown) {
setMarkdown(value);
}
}, [value]);
const getHtml = () => { const getHtml = () => {
return previewRef.current?.getHtml(); return previewRef.current?.getHtml();
}; };
@ -103,6 +94,7 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (
<> <>
<div className={classNames('md-editor-wrap rounded', className)}> <div className={classNames('md-editor-wrap rounded', className)}>
<EditorContext.Provider value={editor}> <EditorContext.Provider value={editor}>
{editor && (
<PluginRender <PluginRender
type="editor" type="editor"
className="toolbar-wrap px-3 d-flex align-items-center flex-wrap" className="toolbar-wrap px-3 d-flex align-items-center flex-wrap"
@ -126,6 +118,7 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (
<div className="toolbar-divider" /> <div className="toolbar-divider" />
<Help /> <Help />
</PluginRender> </PluginRender>
)}
</EditorContext.Provider> </EditorContext.Provider>
<div className="content-wrap"> <div className="content-wrap">
@ -135,7 +128,7 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (
/> />
</div> </div>
</div> </div>
<Viewer ref={previewRef} value={markdown} /> <Viewer ref={previewRef} value={value} />
</> </>
); );
}; };

View File

@ -127,7 +127,8 @@ export const useEditor = ({
onFocus, onFocus,
onBlur, onBlur,
}) => { }) => {
const [editor, setEditor] = useState<Editor>(); const [editor, setEditor] = useState<CodeMirror.Editor | null>(null);
const [value, setValue] = useState<string>('');
const onEnter = (cm) => { const onEnter = (cm) => {
const cursor = cm.getCursor(); const cursor = cm.getCursor();
@ -168,13 +169,13 @@ export const useEditor = ({
placeholder, placeholder,
focus: autoFocus, focus: autoFocus,
}); });
setEditor(cm);
setEditor(cm);
createEditorUtils(codeMirror, cm); createEditorUtils(codeMirror, cm);
cm.on('change', (e) => { cm.on('change', (e) => {
const newValue = e.getValue(); const newValue = e.getValue();
onChange?.(newValue); setValue(newValue);
}); });
cm.on('focus', () => { cm.on('focus', () => {
@ -187,8 +188,13 @@ export const useEditor = ({
cm.addKeyMap({ cm.addKeyMap({
Enter: onEnter, Enter: onEnter,
}); });
return cm;
}; };
useEffect(() => {
onChange?.(value);
}, [value]);
useEffect(() => { useEffect(() => {
if (!(editorRef.current instanceof HTMLElement)) { if (!(editorRef.current instanceof HTMLElement)) {
return; return;

View File

@ -322,10 +322,6 @@ img[src=""] {
vertical-align: -0.125em; vertical-align: -0.125em;
} }
.algoliaSvg { .max-width-200 {
display: inline-block; max-width: 200px;
width: 92px;
height: 24px;
fill: currentColor;
vertical-align: -0.125em;
} }

View File

@ -0,0 +1,7 @@
import { HttpErrorContent } from '@/components';
const Index = () => {
return <HttpErrorContent httpCode="403" />;
};
export default Index;

View File

@ -15,13 +15,11 @@ const pluginInfo: PluginInfo = {
}; };
const Index: FC = () => { const Index: FC = () => {
console.log(111111);
const { t } = useTranslation(getTransNs(), { const { t } = useTranslation(getTransNs(), {
keyPrefix: getTransKeyPrefix(pluginInfo), keyPrefix: getTransKeyPrefix(pluginInfo),
}); });
const { data } = useGetSearchPLuginInfo(); const { data } = useGetSearchPLuginInfo();
console.log(data);
// if (!data?.icon) return null; // if (!data?.icon) return null;
return ( return (
@ -31,7 +29,7 @@ const Index: FC = () => {
target="_blank" target="_blank"
rel="noopener noreferrer"> rel="noopener noreferrer">
<span className="small text-secondary me-2">{t('search_by')}</span> <span className="small text-secondary me-2">{t('search_by')}</span>
<SvgIcon base64={data?.icon} /> <SvgIcon base64={data?.icon} svgClassName="max-width-200" />
</a> </a>
); );
}; };

View File

@ -394,6 +394,10 @@ const routes: RouteNode[] = [
path: '50x', path: '50x',
page: 'pages/50X', page: 'pages/50X',
}, },
{
path: '403',
page: 'pages/403',
},
], ],
}, },
{ {