mirror of https://github.com/fantasticit/think.git
feat: add ctrl+s toast in editor
parent
b807f73bc3
commit
a67e2d7837
|
@ -2,7 +2,7 @@ import Router from 'next/router';
|
||||||
import React, { useMemo, useEffect, useState, useRef } from 'react';
|
import React, { useMemo, useEffect, useState, useRef } from 'react';
|
||||||
import cls from 'classnames';
|
import cls from 'classnames';
|
||||||
import { useEditor, EditorContent } from '@tiptap/react';
|
import { useEditor, EditorContent } from '@tiptap/react';
|
||||||
import { BackTop } from '@douyinfe/semi-ui';
|
import { BackTop, Toast } from '@douyinfe/semi-ui';
|
||||||
import { ILoginUser, IAuthority } from '@think/domains';
|
import { ILoginUser, IAuthority } from '@think/domains';
|
||||||
import { useToggle } from 'hooks/use-toggle';
|
import { useToggle } from 'hooks/use-toggle';
|
||||||
import { useNetwork } from 'hooks/use-network';
|
import { useNetwork } from 'hooks/use-network';
|
||||||
|
@ -22,6 +22,7 @@ import { findMentions } from 'tiptap/utils/find-mention';
|
||||||
import { useCollaborationDocument } from 'data/document';
|
import { useCollaborationDocument } from 'data/document';
|
||||||
import { DataRender } from 'components/data-render';
|
import { DataRender } from 'components/data-render';
|
||||||
import { Banner } from 'components/banner';
|
import { Banner } from 'components/banner';
|
||||||
|
import { LogoName } from 'components/logo';
|
||||||
import { debounce } from 'helpers/debounce';
|
import { debounce } from 'helpers/debounce';
|
||||||
import { event, triggerChangeDocumentTitle, triggerJoinUser, USE_DOCUMENT_VERSION } from 'event';
|
import { event, triggerChangeDocumentTitle, triggerJoinUser, USE_DOCUMENT_VERSION } from 'event';
|
||||||
import { DocumentUserSetting } from './users';
|
import { DocumentUserSetting } from './users';
|
||||||
|
@ -158,6 +159,22 @@ export const Editor: React.FC<IProps> = ({ user: currentUser, documentId, author
|
||||||
};
|
};
|
||||||
}, [editor, users, currentUser]);
|
}, [editor, users, currentUser]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const listener = (event: KeyboardEvent) => {
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.keyCode == 83) {
|
||||||
|
event.preventDefault();
|
||||||
|
Toast.info(`${LogoName}会实时保存你的数据,无需手动保存。`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.document.addEventListener('keydown', listener);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.document.removeEventListener('keydown', listener);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataRender
|
<DataRender
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import styles from './index.module.scss';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
|
export const LogoName = '云策文档';
|
||||||
|
|
||||||
export const LogoImage = () => {
|
export const LogoImage = () => {
|
||||||
return (
|
return (
|
||||||
<Link href={'/'} as={'/'}>
|
<Link href={'/'} as={'/'}>
|
||||||
|
@ -35,7 +37,7 @@ export const LogoText = () => {
|
||||||
return (
|
return (
|
||||||
<Link href={'/'} as={'/'}>
|
<Link href={'/'} as={'/'}>
|
||||||
<a className={styles.wrap}>
|
<a className={styles.wrap}>
|
||||||
<Text>云策文档</Text>
|
<Text>{LogoName}</Text>
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
Popover,
|
Popover,
|
||||||
Popconfirm,
|
Popconfirm,
|
||||||
BackTop,
|
BackTop,
|
||||||
|
Toast,
|
||||||
} from '@douyinfe/semi-ui';
|
} from '@douyinfe/semi-ui';
|
||||||
import { IconChevronLeft, IconArticle } from '@douyinfe/semi-icons';
|
import { IconChevronLeft, IconArticle } from '@douyinfe/semi-icons';
|
||||||
import { ILoginUser, ITemplate } from '@think/domains';
|
import { ILoginUser, ITemplate } from '@think/domains';
|
||||||
|
@ -22,6 +23,7 @@ import { BaseKit, DocumentWithTitle, getCollaborationExtension, getProvider, Men
|
||||||
import { DataRender } from 'components/data-render';
|
import { DataRender } from 'components/data-render';
|
||||||
import { User } from 'components/user';
|
import { User } from 'components/user';
|
||||||
import { DocumentStyle } from 'components/document/style';
|
import { DocumentStyle } from 'components/document/style';
|
||||||
|
import { LogoName } from 'components/logo';
|
||||||
import { useDocumentStyle } from 'hooks/use-document-style';
|
import { useDocumentStyle } from 'hooks/use-document-style';
|
||||||
import { useWindowSize } from 'hooks/use-window-size';
|
import { useWindowSize } from 'hooks/use-window-size';
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
@ -81,6 +83,22 @@ export const Editor: React.FC<IProps> = ({ user, data, loading, error, updateTem
|
||||||
setPublic(data.isPublic);
|
setPublic(data.isPublic);
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const listener = (event: KeyboardEvent) => {
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.keyCode == 83) {
|
||||||
|
event.preventDefault();
|
||||||
|
Toast.info(`${LogoName}会实时保存你的数据,无需手动保存。`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.document.addEventListener('keydown', listener);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.document.removeEventListener('keydown', listener);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
<header>
|
<header>
|
||||||
|
|
Loading…
Reference in New Issue