Skip to content

Commit 3ce92f2

Browse files
committed
feat(mobile): all docs page ui impl (#7976)
1 parent db76780 commit 3ce92f2

File tree

45 files changed

+1064
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1064
-42
lines changed

packages/frontend/core/src/components/page-list/components/page-display-menu.tsx

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ type GroupOption = {
1818
label: string;
1919
};
2020

21+
export function getGroupOptions(t: ReturnType<typeof useI18n>) {
22+
return [
23+
{
24+
value: 'createDate',
25+
label: t['Created'](),
26+
},
27+
{
28+
value: 'updatedDate',
29+
label: t['Updated'](),
30+
},
31+
{
32+
value: 'tag',
33+
label: t['com.affine.page.display.grouping.group-by-tag'](),
34+
},
35+
{
36+
value: 'favourites',
37+
label: t['com.affine.page.display.grouping.group-by-favourites'](),
38+
},
39+
{
40+
value: 'none',
41+
label: t['com.affine.page.display.grouping.no-grouping'](),
42+
},
43+
] satisfies GroupOption[];
44+
}
45+
2146
export const PageDisplayMenu = () => {
2247
const t = useI18n();
2348
const [workspaceProperties, setProperties] = useAllDocDisplayProperties();
@@ -66,28 +91,7 @@ export const PageDisplayMenu = () => {
6691
}, [handleSetDocDisplayProperties, t]);
6792

6893
const items = useMemo(() => {
69-
const groupOptions: GroupOption[] = [
70-
{
71-
value: 'createDate',
72-
label: t['Created'](),
73-
},
74-
{
75-
value: 'updatedDate',
76-
label: t['Updated'](),
77-
},
78-
{
79-
value: 'tag',
80-
label: t['com.affine.page.display.grouping.group-by-tag'](),
81-
},
82-
{
83-
value: 'favourites',
84-
label: t['com.affine.page.display.grouping.group-by-favourites'](),
85-
},
86-
{
87-
value: 'none',
88-
label: t['com.affine.page.display.grouping.no-grouping'](),
89-
},
90-
];
94+
const groupOptions: GroupOption[] = getGroupOptions(t);
9195

9296
const subItems = groupOptions.map(option => (
9397
<MenuItem

packages/frontend/core/src/components/page-list/use-block-suite-page-preview.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export const getPagePreviewText = (page: Doc) => {
1919
let count = MAX_SEARCH_BLOCK_COUNT;
2020
while (queue.length && previewLenNeeded > 0 && count-- > 0) {
2121
const block = queue.shift();
22+
// if preview length is enough, skip the rest of the blocks
23+
if (preview.join(' ').trim().length >= MAX_PREVIEW_LENGTH) {
24+
break;
25+
}
2226
if (!block) {
2327
console.error('Unexpected empty block');
2428
break;
@@ -51,7 +55,7 @@ export const getPagePreviewText = (page: Doc) => {
5155
}
5256
}
5357
}
54-
return preview.join(' ').slice(0, MAX_PREVIEW_LENGTH);
58+
return preview.join(' ').trim().slice(0, MAX_PREVIEW_LENGTH);
5559
};
5660

5761
const emptyAtom = atom<string>('');

packages/frontend/core/src/modules/workbench/view/workbench-link.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ export type WorkbenchLinkProps = React.PropsWithChildren<
1414
{
1515
to: To;
1616
onClick?: (e: MouseEvent) => void;
17+
replaceHistory?: boolean;
1718
} & React.HTMLProps<HTMLAnchorElement>
1819
>;
1920

2021
export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
21-
function WorkbenchLink({ to, onClick, ...other }, ref) {
22+
function WorkbenchLink({ to, onClick, replaceHistory, ...other }, ref) {
2223
const { featureFlagService, workbenchService } = useServices({
2324
FeatureFlagService,
2425
WorkbenchService,
@@ -45,10 +46,10 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
4546
}
4647
return 'active';
4748
})();
48-
workbench.open(to, { at });
49+
workbench.open(to, { at, replaceHistory });
4950
event.preventDefault();
5051
},
51-
[enableMultiView, onClick, to, workbench]
52+
[enableMultiView, onClick, replaceHistory, to, workbench]
5253
);
5354

5455
// eslint suspicious runtime error

packages/frontend/core/src/pages/workspace/collection/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const Component = function CollectionPage() {
121121
if (!collection) {
122122
return null;
123123
}
124-
const inner = isEmpty(collection) ? (
124+
const inner = isEmptyCollection(collection) ? (
125125
<Placeholder collection={collection} />
126126
) : (
127127
<CollectionDetail collection={collection} />
@@ -346,7 +346,7 @@ const Placeholder = ({ collection }: { collection: Collection }) => {
346346
);
347347
};
348348

349-
const isEmpty = (collection: Collection) => {
349+
export const isEmptyCollection = (collection: Collection) => {
350350
return (
351351
collection.allowList.length === 0 && collection.filterList.length === 0
352352
);

packages/frontend/mobile/src/components/app-tabs/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from '@affine/core/modules/workbench';
55
import { AllDocsIcon, SearchIcon } from '@blocksuite/icons/rc';
66
import { useLiveData, useService } from '@toeverything/infra';
7+
import type { Location } from 'react-router-dom';
78

89
import { HomeIcon } from './home-icon';
910
import * as styles from './styles.css';
@@ -12,6 +13,7 @@ interface Route {
1213
to: string;
1314
Icon: React.FC;
1415
LinkComponent?: React.FC;
16+
isActive?: (location: Location) => boolean;
1517
}
1618

1719
const routes: Route[] = [
@@ -22,6 +24,10 @@ const routes: Route[] = [
2224
{
2325
to: '/all',
2426
Icon: AllDocsIcon,
27+
isActive: location =>
28+
location.pathname === '/all' ||
29+
location.pathname.startsWith('/collection') ||
30+
location.pathname.startsWith('/tag'),
2531
},
2632
{
2733
to: '/search',
@@ -37,9 +43,13 @@ export const AppTabs = () => {
3743
<ul className={styles.appTabs} id="app-tabs">
3844
{routes.map(route => {
3945
const Link = route.LinkComponent || WorkbenchLink;
46+
47+
const isActive = route.isActive
48+
? route.isActive(location)
49+
: location.pathname === route.to;
4050
return (
4151
<Link
42-
data-active={location.pathname === route.to}
52+
data-active={isActive}
4353
to={route.to}
4454
key={route.to}
4555
className={styles.tabItem}

packages/frontend/mobile/src/components/app-tabs/styles.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const appTabs = style({
1818

1919
position: 'fixed',
2020
bottom: 0,
21+
zIndex: 1,
2122
});
2223
export const tabItem = style({
2324
display: 'flex',

packages/frontend/mobile/src/components/doc-card/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import { DocCardTags } from './tag';
1616

1717
export interface DocCardProps extends Omit<WorkbenchLinkProps, 'to'> {
1818
meta: DocMeta;
19+
showTags?: boolean;
1920
}
2021

2122
export const DocCard = forwardRef<HTMLAnchorElement, DocCardProps>(
22-
function DocCard({ meta, className, ...attrs }, ref) {
23+
function DocCard({ showTags = true, meta, className, ...attrs }, ref) {
2324
const favAdapter = useService(CompatibleFavoriteItemsAdapter);
2425
const workspace = useService(WorkspaceService).workspace;
2526

@@ -54,7 +55,7 @@ export const DocCard = forwardRef<HTMLAnchorElement, DocCardProps>(
5455
emptyFallback={<div className={styles.contentEmpty}>Empty</div>}
5556
/>
5657
</main>
57-
<DocCardTags docId={meta.id} rows={2} />
58+
{showTags ? <DocCardTags docId={meta.id} rows={2} /> : null}
5859
</WorkbenchLink>
5960
);
6061
}

packages/frontend/mobile/src/components/doc-card/tag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const DocCardTagsRenderer = ({ tags, rows }: { tags: Tag[]; rows: number }) => {
122122
{tags.map(tag => (
123123
<DocCardTag key={tag.id} tag={tag} />
124124
))}
125-
{/* TODO: more icon */}
125+
{/* TODO(@CatsJuice): more icon */}
126126
{/* <MoreHorizontalIcon /> */}
127127
</ul>
128128
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './app-tabs';
2+
export * from './doc-card';
23
export * from './page-header';
34
export * from './search-button';
45
export * from './workspace-selector';

packages/frontend/mobile/src/components/page-header/styles.css.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1+
import { cssVarV2 } from '@toeverything/theme/v2';
12
import { style } from '@vanilla-extract/css';
23

34
export const root = style({
45
width: '100%',
56
minHeight: 44,
67
padding: '0 6px',
8+
paddingTop: 16,
79
display: 'flex',
810
alignItems: 'center',
911
justifyContent: 'space-between',
10-
position: 'relative',
12+
13+
position: 'sticky',
14+
top: 0,
15+
zIndex: 1,
16+
backgroundColor: cssVarV2('layer/background/secondary'),
1117
});
1218
export const content = style({
1319
selectors: {
1420
'&.center': {
1521
position: 'absolute',
1622
left: '50%',
1723
transform: 'translateX(-50%)',
24+
width: 'fit-content',
25+
maxWidth: 'calc(100% - 12px - 88px - 16px)',
26+
display: 'flex',
27+
justifyContent: 'center',
28+
pointerEvents: 'none',
1829
},
1930
'&:not(.center)': {
2031
width: 0,

0 commit comments

Comments
 (0)