From e6530f5017022ffcb8af6cb2e84a9c711029cfd2 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Fri, 7 Jul 2023 21:16:49 +0800 Subject: [PATCH] chore: add new item for share component (#3084) (cherry picked from commit 66152401bec999350b29471c0d359a8a19e16088) --- .../page-list/operation-menu-items/export.tsx | 58 ++++++++++++++----- .../src/components/share-menu/export.tsx | 47 ++++----------- .../src/components/share-menu/index.css.ts | 12 ---- 3 files changed, 55 insertions(+), 62 deletions(-) diff --git a/packages/component/src/components/page-list/operation-menu-items/export.tsx b/packages/component/src/components/page-list/operation-menu-items/export.tsx index 5c6fb21e90..0107ae1c00 100644 --- a/packages/component/src/components/page-list/operation-menu-items/export.tsx +++ b/packages/component/src/components/page-list/operation-menu-items/export.tsx @@ -16,7 +16,7 @@ import { useCallback, useRef } from 'react'; import { Menu, MenuItem } from '../../..'; import type { CommonMenuItemProps } from './types'; -const ExportToPdfMenuItem = ({ +export const ExportToPdfMenuItem = ({ onSelect, }: CommonMenuItemProps<{ type: 'pdf' }>) => { const t = useAFFiNEI18N(); @@ -91,12 +91,13 @@ const ExportToPdfMenuItem = ({ ); }; -const ExportToHtmlMenuItem = ({ +export const ExportToHtmlMenuItem = ({ onSelect, }: CommonMenuItemProps<{ type: 'html' }>) => { const t = useAFFiNEI18N(); const contentParserRef = useRef(); const { currentEditor } = globalThis; + const setPushNotification = useSetAtom(pushNotificationAtom); const onClickExportHtml = useCallback(() => { if (!currentEditor) { return; @@ -104,11 +105,22 @@ const ExportToHtmlMenuItem = ({ if (!contentParserRef.current) { contentParserRef.current = new ContentParser(currentEditor.page); } - contentParserRef.current.exportHtml().catch(err => { - console.error(err); - }); + contentParserRef.current + .exportHtml() + .then(() => { + onSelect?.({ type: 'html' }); + setPushNotification({ + key: 'export-to-html', + title: t['com.affine.export.success.title'](), + message: t['com.affine.export.success.message'](), + type: 'success', + }); + }) + .catch(err => { + console.error(err); + }); onSelect?.({ type: 'html' }); - }, [onSelect, currentEditor]); + }, [currentEditor, onSelect, setPushNotification, t]); return ( <> ) => { const t = useAFFiNEI18N(); @@ -143,7 +155,7 @@ const ExportToPngMenuItem = ({ .then(() => { onSelect?.({ type: 'png' }); setPushNotification({ - key: 'export-to-pdf', + key: 'export-to-png', title: t['com.affine.export.success.title'](), message: t['com.affine.export.success.message'](), type: 'success', @@ -152,7 +164,7 @@ const ExportToPngMenuItem = ({ .catch(err => { console.error(err); setPushNotification({ - key: 'export-to-pdf', + key: 'export-to-png', title: t['com.affine.export.error.title'](), message: t['com.affine.export.error.message'](), type: 'error', @@ -173,12 +185,13 @@ const ExportToPngMenuItem = ({ ); }; -const ExportToMarkdownMenuItem = ({ +export const ExportToMarkdownMenuItem = ({ onSelect, }: CommonMenuItemProps<{ type: 'markdown' }>) => { const t = useAFFiNEI18N(); const contentParserRef = useRef(); const { currentEditor } = globalThis; + const setPushNotification = useSetAtom(pushNotificationAtom); const onClickExportMarkdown = useCallback(() => { if (!currentEditor) { return; @@ -186,11 +199,28 @@ const ExportToMarkdownMenuItem = ({ if (!contentParserRef.current) { contentParserRef.current = new ContentParser(currentEditor.page); } - contentParserRef.current.exportMarkdown().catch(err => { - console.error(err); - }); + contentParserRef.current + .exportMarkdown() + .then(() => { + onSelect?.({ type: 'markdown' }); + setPushNotification({ + key: 'export-to-markdown', + title: t['com.affine.export.success.title'](), + message: t['com.affine.export.success.message'](), + type: 'success', + }); + }) + .catch(err => { + console.error(err); + setPushNotification({ + key: 'export-to-markdown', + title: t['com.affine.export.error.title'](), + message: t['com.affine.export.error.message'](), + type: 'error', + }); + }); onSelect?.({ type: 'markdown' }); - }, [onSelect, currentEditor]); + }, [currentEditor, onSelect, setPushNotification, t]); return ( <> = props => { - const contentParserRef = useRef(); +export const Export: FC = () => { const t = useAFFiNEI18N(); return (
@@ -23,30 +18,10 @@ export const Export: FC = props => { {t['Export Shared Pages Description']()}
- - + + + +
); diff --git a/packages/component/src/components/share-menu/index.css.ts b/packages/component/src/components/share-menu/index.css.ts index 569d206761..bf9d585e7a 100644 --- a/packages/component/src/components/share-menu/index.css.ts +++ b/packages/component/src/components/share-menu/index.css.ts @@ -52,15 +52,3 @@ export const inputButtonRowStyle = style({ alignItems: 'center', marginTop: '16px', }); -export const exportButtonStyle = style({ - display: 'flex', - justifyContent: 'center', - alignItems: 'center', - padding: '0', - border: 'none', -}); -export const svgStyle = style({ - fontSize: '20px', - marginRight: '12px', - verticalAlign: 'top', -});