From ec99a0ce05d504660d1babe7d432646ce4d437a7 Mon Sep 17 00:00:00 2001 From: Whitewater Date: Thu, 8 Jun 2023 05:28:37 -0700 Subject: [PATCH] feat: update desc for empty page (#2710) --- .../block-suite-page-list/index.css.ts | 22 +++++++++++ .../block-suite-page-list/index.tsx | 37 ++++++++++++++++--- packages/component/src/ui/empty/empty.tsx | 23 ++++++++++-- packages/i18n/src/resources/en.json | 4 +- .../src/stories/page-list.stories.tsx | 18 ++++++++- 5 files changed, 94 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/blocksuite/block-suite-page-list/index.css.ts b/apps/web/src/components/blocksuite/block-suite-page-list/index.css.ts index c1dd7ea1c2..7396dee140 100644 --- a/apps/web/src/components/blocksuite/block-suite-page-list/index.css.ts +++ b/apps/web/src/components/blocksuite/block-suite-page-list/index.css.ts @@ -3,3 +3,25 @@ import { style } from '@vanilla-extract/css'; export const pageListEmptyStyle = style({ height: 'calc(100% - 52px)', }); + +export const emptyDescButton = style({ + cursor: 'pointer', + color: 'var(--affine-text-secondary-color)', + background: 'var(--affine-background-code-block)', + border: '1px solid var(--affine-border-color)', + borderRadius: '4px', + padding: '0 6px', + boxSizing: 'border-box', + selectors: { + '&:hover': { + background: 'var(--affine-hover-color)', + }, + }, +}); + +export const emptyDescKbd = style([ + emptyDescButton, + { + cursor: 'text', + }, +]); diff --git a/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx b/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx index c00a83483c..ab70da6adf 100644 --- a/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx +++ b/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx @@ -5,7 +5,9 @@ import { PageList, PageListTrashView, } from '@affine/component/page-list'; +import { env } from '@affine/env'; import type { View } from '@affine/env/filter'; +import { Trans } from '@affine/i18n'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { EdgelessIcon, PageIcon } from '@blocksuite/icons'; import type { PageMeta } from '@blocksuite/store'; @@ -19,7 +21,7 @@ import { pageModeSelectAtom } from '../../../atoms'; import { useBlockSuiteMetaHelper } from '../../../hooks/affine/use-block-suite-meta-helper'; import type { BlockSuiteWorkspace } from '../../../shared'; import { toast } from '../../../utils'; -import { pageListEmptyStyle } from './index.css'; +import { emptyDescButton, emptyDescKbd, pageListEmptyStyle } from './index.css'; import { usePageHelper } from './utils'; export type BlockSuitePageListProps = { @@ -41,14 +43,36 @@ const filter = { }; const PageListEmpty = (props: { + createPage?: () => void; listType: BlockSuitePageListProps['listType']; }) => { - const { listType } = props; + const { listType, createPage } = props; const t = useAFFiNEI18N(); const getEmptyDescription = () => { if (listType === 'all') { - return t['emptyAllPages'](); + const CreateNewPageButton = () => ( + + ); + if (env.isDesktop) { + const shortcut = env.isMacOs ? '⌘ + N' : 'Ctrl + N'; + return ( + + Click on the button Or press + {{ shortcut } as any} to create + your first page. + + ); + } + return ( + + Click on the + + button to create your first page. + + ); } if (listType === 'trash') { return t['emptyTrash'](); @@ -60,7 +84,10 @@ const PageListEmpty = (props: { return (
- +
); }; @@ -204,7 +231,7 @@ export const BlockSuitePageList: React.FC = ({ onImportFile={importFile} isPublicWorkspace={isPublic} list={pageList} - fallback={} + fallback={} /> ); }; diff --git a/packages/component/src/ui/empty/empty.tsx b/packages/component/src/ui/empty/empty.tsx index ee02b577a4..4ded257b03 100644 --- a/packages/component/src/ui/empty/empty.tsx +++ b/packages/component/src/ui/empty/empty.tsx @@ -1,15 +1,17 @@ -import type { CSSProperties } from 'react'; +import type { CSSProperties, ReactNode } from 'react'; import { EmptySvg } from './empty-svg'; import { StyledEmptyContainer } from './style'; export type EmptyContentProps = { containerStyle?: CSSProperties; - description?: string; + title?: ReactNode; + description?: ReactNode; descriptionStyle?: CSSProperties; }; export const Empty = ({ containerStyle, + title, description, descriptionStyle, }: EmptyContentProps) => { @@ -18,7 +20,22 @@ export const Empty = ({
-

{description}

+ {title && ( +

+ {title} +

+ )} + {description && ( +

+ {description} +

+ )} ); }; diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 9bc9eb85a3..34650df38b 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -116,7 +116,8 @@ "mobile device": "Looks like you are browsing on a mobile device.", "mobile device description": "We are still working on mobile support and recommend you use a desktop device.", "Got it": "Got it", - "emptyAllPages": "This workspace is empty. Create a new page to begin editing.", + "emptyAllPages": "Click on the <1>$t(New Page) button to create your first page.", + "emptyAllPagesClient": "Click on the <1>$t(New Page) button Or press <3>{{shortcut}} to create your first page.", "emptyTrash": "Click Add to Trash and the page will appear here.", "still designed": "(This page is still being designed.)", "My Workspaces": "My Workspaces", @@ -290,6 +291,7 @@ "com.affine.last30Days": "Last 30 Days", "com.affine.currentYear": "Current Year", "com.affine.earlier": "Earlier", + "com.affine.emptyDesc": "There's no page here yet", "FILE_ALREADY_EXISTS": "File already exists", "others": "Others", "Update Available": "Update available", diff --git a/packages/storybook/src/stories/page-list.stories.tsx b/packages/storybook/src/stories/page-list.stories.tsx index 87c57af42f..7f32f097af 100644 --- a/packages/storybook/src/stories/page-list.stories.tsx +++ b/packages/storybook/src/stories/page-list.stories.tsx @@ -138,7 +138,23 @@ AffineEmptyAllPageList.args = { onCreateNewEdgeless: () => toast('Create new edgeless'), onImportFile: () => toast('Import file'), list: [], - fallback: , + fallback: ( + + empty description, click{' '} + + + } + /> + ), }; export const AffinePublicPageList: StoryFn = ({