mirror of https://github.com/fantasticit/think.git
client: fix #issuecomment-1158885416
This commit is contained in:
parent
9a6c1c40e6
commit
53bfef34b4
|
@ -8,7 +8,7 @@ import { prosemirrorJSONToYDoc } from 'tiptap/core/thritypart/y-prosemirror/y-pr
|
|||
import { markdownToProsemirror } from 'tiptap/markdown/markdown-to-prosemirror';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
export const ImportEditor = ({ content, onChange }) => {
|
||||
export const ImportEditor = ({ content, onChange, onError }) => {
|
||||
const parsed = useRef(false);
|
||||
const ydoc = useMemo(() => new Y.Doc(), []);
|
||||
const editor = useEditor(
|
||||
|
@ -39,14 +39,16 @@ export const ImportEditor = ({ content, onChange }) => {
|
|||
|
||||
parsed.current = true;
|
||||
} catch (e) {
|
||||
Toast.error('文件内容解析失败,请到 Github 提 issue 寻求解决!');
|
||||
onError();
|
||||
console.error(e.message, e.stack);
|
||||
Toast.error('文件内容解析失败,请打开控制台,截图错误信息,请到 Github 提 issue 寻求解决!');
|
||||
}
|
||||
|
||||
return () => {
|
||||
ydoc.destroy();
|
||||
editor.destroy();
|
||||
};
|
||||
}, [editor, ydoc, content, onChange]);
|
||||
}, [editor, ydoc, content, onChange, onError]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
|
|
@ -67,6 +67,18 @@ export const Import: React.FC<IProps> = ({ wikiId }) => {
|
|||
};
|
||||
}, []);
|
||||
|
||||
const onParsedFileError = useCallback((filename) => {
|
||||
return () => {
|
||||
setUploadFiles((files) => {
|
||||
return files.filter((name) => name !== filename);
|
||||
});
|
||||
setTexts((texts) => {
|
||||
delete texts[filename];
|
||||
return texts;
|
||||
});
|
||||
};
|
||||
}, []);
|
||||
|
||||
const onDeleteFile = useCallback((toDeleteFilename) => {
|
||||
return () => {
|
||||
setPayloads((payloads) => {
|
||||
|
@ -112,7 +124,14 @@ export const Import: React.FC<IProps> = ({ wikiId }) => {
|
|||
<input ref={$upload} type="file" hidden multiple accept="text/markdown" onChange={handleFile} />
|
||||
|
||||
{uploadFiles.map((filename) => {
|
||||
return <ImportEditor key={filename} content={texts[filename]} onChange={onParsedFile(filename)} />;
|
||||
return (
|
||||
<ImportEditor
|
||||
key={filename}
|
||||
content={texts[filename]}
|
||||
onChange={onParsedFile(filename)}
|
||||
onError={onParsedFileError(filename)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
<List
|
||||
|
|
|
@ -117,6 +117,5 @@ export const AllExtensions = [
|
|||
Status,
|
||||
DocumentWithTitle,
|
||||
Title,
|
||||
Document,
|
||||
Flow,
|
||||
];
|
||||
|
|
|
@ -256,7 +256,7 @@ function table(state, startLine, endLine, silent) {
|
|||
|
||||
token = state.push('paragraph_open', 'p', 1);
|
||||
token = state.push('inline', '', 0);
|
||||
token.content = columns[i].trim();
|
||||
token.content = (columns[i] || '').trim();
|
||||
token.children = [];
|
||||
token = state.push('paragraph_close', 'p', -1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue