feat: page list supports preview (#2606)

This commit is contained in:
Whitewater
2023-05-30 21:24:55 -07:00
committed by GitHub
parent 8dbd354659
commit 855fd8a73a
6 changed files with 50 additions and 8 deletions

View File

@@ -197,6 +197,7 @@ export const PageListTrashView: React.FC<{
{ {
pageId, pageId,
title, title,
preview,
icon, icon,
createDate, createDate,
trashDate, trashDate,
@@ -214,6 +215,7 @@ export const PageListTrashView: React.FC<{
<TitleCell <TitleCell
icon={icon} icon={icon}
text={title || t['Untitled']()} text={title || t['Untitled']()}
desc={preview}
onClick={onClickPage} onClick={onClickPage}
/> />
<TableCell onClick={onClickPage}>{formatDate(createDate)}</TableCell> <TableCell onClick={onClickPage}>{formatDate(createDate)}</TableCell>

View File

@@ -49,6 +49,7 @@ export const AllPagesBody = ({
groupName, groupName,
pageId, pageId,
title, title,
preview,
icon, icon,
isPublicPage, isPublicPage,
favorite, favorite,
@@ -80,6 +81,7 @@ export const AllPagesBody = ({
}} }}
icon={icon} icon={icon}
text={displayTitle} text={displayTitle}
desc={preview}
data-testid="title" data-testid="title"
onClick={onClickPage} onClick={onClickPage}
/> />

View File

@@ -2,11 +2,16 @@ import type { TableCellProps } from '@affine/component';
import { Content, TableCell } from '@affine/component'; import { Content, TableCell } from '@affine/component';
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
import { StyledTitleLink } from '../styles'; import {
StyledTitleContentWrapper,
StyledTitleLink,
StyledTitlePreview,
} from '../styles';
type TitleCellProps = { type TitleCellProps = {
icon: JSX.Element; icon: JSX.Element;
text: string; text: string;
desc?: string;
suffix?: JSX.Element; suffix?: JSX.Element;
/** /**
* Customize the children of the cell * Customize the children of the cell
@@ -17,22 +22,29 @@ type TitleCellProps = {
} & Omit<TableCellProps, 'children'>; } & Omit<TableCellProps, 'children'>;
export const TitleCell = React.forwardRef<HTMLTableCellElement, TitleCellProps>( export const TitleCell = React.forwardRef<HTMLTableCellElement, TitleCellProps>(
({ icon, text, suffix, children: render, ...props }, ref) => { ({ icon, text, desc, suffix, children: render, ...props }, ref) => {
const renderChildren = useCallback(() => { const renderChildren = useCallback(() => {
const childElement = ( const childElement = (
<> <>
<StyledTitleLink> <StyledTitleLink>
{icon} {icon}
<Content ellipsis={true} color="inherit"> <StyledTitleContentWrapper>
{text} <Content ellipsis={true} maxWidth="100%" color="inherit">
</Content> {text}
</Content>
{desc && (
<StyledTitlePreview ellipsis={true} color="inherit">
{desc}
</StyledTitlePreview>
)}
</StyledTitleContentWrapper>
</StyledTitleLink> </StyledTitleLink>
{suffix} {suffix}
</> </>
); );
return render ? render(childElement) : childElement; return render ? render(childElement) : childElement;
}, [icon, render, suffix, text]); }, [desc, icon, render, suffix, text]);
return ( return (
<TableCell ref={ref} {...props}> <TableCell ref={ref} {...props}>

View File

@@ -1,4 +1,4 @@
import { displayFlex, styled } from '@affine/component'; import { Content, displayFlex, styled } from '@affine/component';
import { TableRow } from '@affine/component'; import { TableRow } from '@affine/component';
export const StyledTableContainer = styled('div')(({ theme }) => { export const StyledTableContainer = styled('div')(({ theme }) => {
@@ -50,6 +50,24 @@ export const StyledTitleLink = styled('div')(() => {
}; };
}); });
export const StyledTitleContentWrapper = styled('div')(() => {
return {
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
width: '100%',
overflow: 'hidden',
};
});
export const StyledTitlePreview = styled(Content)(() => {
return {
fontWeight: 400,
fontSize: 'var(--affine-font-xs)',
maxWidth: '100%',
};
});
export const StyledTableRow = styled(TableRow)(() => { export const StyledTableRow = styled(TableRow)(() => {
return { return {
cursor: 'pointer', cursor: 'pointer',

View File

@@ -11,6 +11,7 @@ export type ListData = {
pageId: string; pageId: string;
icon: JSX.Element; icon: JSX.Element;
title: string; title: string;
preview?: string;
favorite: boolean; favorite: boolean;
createDate: Date; createDate: Date;
updatedDate: Date; updatedDate: Date;
@@ -28,6 +29,7 @@ export type TrashListData = {
pageId: string; pageId: string;
icon: JSX.Element; icon: JSX.Element;
title: string; title: string;
preview?: string;
createDate: Date; createDate: Date;
// TODO remove optional after assert that trashDate is always set // TODO remove optional after assert that trashDate is always set
trashDate?: Date; trashDate?: Date;
@@ -47,5 +49,6 @@ export type PageListProps = {
export type DraggableTitleCellData = { export type DraggableTitleCellData = {
pageId: string; pageId: string;
pageTitle: string; pageTitle: string;
pagePreview?: string;
icon: React.ReactElement; icon: React.ReactElement;
}; };

View File

@@ -71,6 +71,7 @@ AffineAllPageList.args = {
icon: <PageIcon />, icon: <PageIcon />,
isPublicPage: true, isPublicPage: true,
title: 'Today Page', title: 'Today Page',
preview: 'this is page preview',
createDate: new Date(), createDate: new Date(),
updatedDate: new Date(), updatedDate: new Date(),
bookmarkPage: () => toast('Bookmark page'), bookmarkPage: () => toast('Bookmark page'),
@@ -84,7 +85,10 @@ AffineAllPageList.args = {
favorite: false, favorite: false,
icon: <PageIcon />, icon: <PageIcon />,
isPublicPage: true, isPublicPage: true,
title: '1 Example Public Page with long title that will be truncated', title:
'1 Example Public Page with long title that will be truncated because it is too too long',
preview:
'this is page preview and it is very long and will be truncated because it is too long and it is very long and will be truncated because it is too long',
createDate: new Date('2021-01-01'), createDate: new Date('2021-01-01'),
updatedDate: new Date('2021-01-02'), updatedDate: new Date('2021-01-02'),
bookmarkPage: () => toast('Bookmark page'), bookmarkPage: () => toast('Bookmark page'),
@@ -139,6 +143,7 @@ AffineTrashPageList.args = {
pageId: '1', pageId: '1',
icon: <PageIcon />, icon: <PageIcon />,
title: 'Example Page', title: 'Example Page',
preview: 'this is trash page preview',
createDate: new Date('2021-01-01'), createDate: new Date('2021-01-01'),
trashDate: new Date('2021-01-01'), trashDate: new Date('2021-01-01'),
onClickPage: () => toast('Click page'), onClickPage: () => toast('Click page'),