From a534e799c132b4c354a1a82300b801e6ad802acf Mon Sep 17 00:00:00 2001 From: fantasticit Date: Wed, 25 May 2022 13:05:24 +0800 Subject: [PATCH] client: improve render editor --- .../src/components/document/editor/index.tsx | 67 ++++------ .../src/components/document/reader/index.tsx | 112 +++++++---------- .../src/components/template/editor/index.tsx | 114 ++++++++---------- .../components/template/editor/jhuhhkh.tsx | 89 -------------- 4 files changed, 119 insertions(+), 263 deletions(-) delete mode 100644 packages/client/src/components/template/editor/jhuhhkh.tsx diff --git a/packages/client/src/components/document/editor/index.tsx b/packages/client/src/components/document/editor/index.tsx index 4509399..10a1892 100644 --- a/packages/client/src/components/document/editor/index.tsx +++ b/packages/client/src/components/document/editor/index.tsx @@ -51,19 +51,18 @@ export const DocumentEditor: React.FC = ({ documentId }) => { }, [document, documentId]); const actions = useMemo( - () => - docAuthLoading ? null : ( - - {document && authority.readable && ( - - )} - - - - - - ), - [docAuthLoading, documentId, document, authority] + () => ( + + {document && authority.readable && ( + + )} + + + + + + ), + [documentId, document, authority] ); useEffect(() => { @@ -120,36 +119,18 @@ export const DocumentEditor: React.FC = ({ documentId }) => { {isMobile &&
{actions}
}
- - - {/* FIXME: semi-design 的问题,不加 div,文字会换行! */} -
-
- - } - error={docAuthError} - errorContent={ -
- -
- } - normalContent={() => { - return ( - <> - - - - ); - }} + {docAuthError && ( +
+ +
+ )} + {document && } +
diff --git a/packages/client/src/components/document/reader/index.tsx b/packages/client/src/components/document/reader/index.tsx index 4a02342..14cee2d 100644 --- a/packages/client/src/components/document/reader/index.tsx +++ b/packages/client/src/components/document/reader/index.tsx @@ -76,34 +76,31 @@ export const DocumentReader: React.FC = ({ documentId }) => { }, [document]); const actions = useMemo( - () => - docAuthLoading ? null : ( - - {document && authority.readable && ( - - )} - {authority && authority.editable && ( - - - - - - - } - > - -
-
-
- {mounted && ( - - )} -
-
-
+ <> + {data && } +
+
+ +
+
+
+
+ {mounted && data && ( + + )}
- - ); - }} - /> +
+
+
+ ); }; diff --git a/packages/client/src/components/template/editor/jhuhhkh.tsx b/packages/client/src/components/template/editor/jhuhhkh.tsx deleted file mode 100644 index d5ed712..0000000 --- a/packages/client/src/components/template/editor/jhuhhkh.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { IconChevronLeft } from '@douyinfe/semi-icons'; -import { Button, Nav, Popconfirm, Space, Switch, Tooltip, Typography } from '@douyinfe/semi-ui'; -import { ILoginUser, ITemplate } from '@think/domains'; -import cls from 'classnames'; -import { DocumentStyle } from 'components/document/style'; -import { Theme } from 'components/theme'; -import { User } from 'components/user'; -import { useDocumentStyle } from 'hooks/use-document-style'; -import { useWindowSize } from 'hooks/use-window-size'; -import Router from 'next/router'; -import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { CollaborationEditor } from 'tiptap/editor'; - -import styles from './index.module.scss'; - -const { Text } = Typography; - -interface IProps { - user: ILoginUser; - data: ITemplate; - updateTemplate: (arg) => Promise; - deleteTemplate: () => Promise; -} - -export const Editor: React.FC = ({ user, data, updateTemplate, deleteTemplate }) => { - const { width: windowWidth } = useWindowSize(); - const [title, setTitle] = useState(data.title); - const [isPublic, setPublic] = useState(false); - const { width, fontSize } = useDocumentStyle(); - const editorWrapClassNames = useMemo(() => { - return width === 'standardWidth' ? styles.isStandardWidth : styles.isFullWidth; - }, [width]); - - const goback = useCallback(() => { - Router.back(); - }, []); - - const handleDelte = useCallback(() => { - deleteTemplate().then(() => { - goback(); - }); - }, [deleteTemplate, goback]); - - useEffect(() => { - if (!data) return; - setPublic(data.isPublic); - }, [data]); - - return ( -
-
- -
-
-
-
- -
-
-
-
- ); -};