Skip to content

Commit a758254

Browse files
committed
✨(frontend) improve mobile UX by showing subdocs count
helps users notice root documents have children in mobile view Signed-off-by: Cyril <c.gromoff@gmail.com>
1 parent 6314cb3 commit a758254

File tree

3 files changed

+84
-47
lines changed

3 files changed

+84
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to
2727
- ✨(frontend) create skeleton component for DocEditor #1491
2828
- ✨(frontend) add an EmojiPicker in the document tree and title #1381
2929
- ✨(frontend) ajustable left panel #1456
30+
- ✨(frontend) improve mobile UX by showing subdocs count #1540
3031

3132
### Changed
3233

src/frontend/apps/impress/src/features/docs/doc-header/components/DocHeader.tsx

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import { useTranslation } from 'react-i18next';
22

3-
import { Box, HorizontalSeparator, Text } from '@/components';
4-
import { useConfig } from '@/core';
3+
import { Box, HorizontalSeparator } from '@/components';
54
import { useCunninghamTheme } from '@/cunningham';
65
import {
76
Doc,
87
LinkReach,
9-
Role,
108
getDocLinkReach,
119
useIsCollaborativeEditable,
12-
useTrans,
1310
} from '@/docs/doc-management';
14-
import { useDate } from '@/hook';
1511
import { useResponsiveStore } from '@/stores';
1612

1713
import { AlertNetwork } from './AlertNetwork';
1814
import { AlertPublic } from './AlertPublic';
1915
import { AlertRestore } from './AlertRestore';
2016
import { BoutonShare } from './BoutonShare';
17+
import { DocHeaderInfo } from './DocHeaderInfo';
2118
import { DocTitle } from './DocTitle';
2219
import { DocToolBox } from './DocToolBox';
2320

@@ -29,27 +26,11 @@ export const DocHeader = ({ doc }: DocHeaderProps) => {
2926
const { spacingsTokens } = useCunninghamTheme();
3027
const { isDesktop } = useResponsiveStore();
3128
const { t } = useTranslation();
32-
const { transRole } = useTrans();
3329
const { isEditable } = useIsCollaborativeEditable(doc);
3430
const docIsPublic = getDocLinkReach(doc) === LinkReach.PUBLIC;
3531
const docIsAuth = getDocLinkReach(doc) === LinkReach.AUTHENTICATED;
36-
const { relativeDate, calculateDaysLeft } = useDate();
37-
const { data: config } = useConfig();
3832
const isDeletedDoc = !!doc.deleted_at;
3933

40-
let dateToDisplay = t('Last update: {{update}}', {
41-
update: relativeDate(doc.updated_at),
42-
});
43-
44-
if (config?.TRASHBIN_CUTOFF_DAYS && doc.deleted_at) {
45-
const daysLeft = calculateDaysLeft(
46-
doc.deleted_at,
47-
config.TRASHBIN_CUTOFF_DAYS,
48-
);
49-
50-
dateToDisplay = `${t('Days remaining:')} ${daysLeft} ${t('days', { count: daysLeft })}`;
51-
}
52-
5334
return (
5435
<>
5536
<Box
@@ -80,33 +61,8 @@ export const DocHeader = ({ doc }: DocHeaderProps) => {
8061
>
8162
<Box $gap={spacingsTokens['3xs']} $overflow="auto">
8263
<DocTitle doc={doc} />
83-
8464
<Box $direction="row">
85-
{isDesktop && (
86-
<>
87-
<Text
88-
$variation="600"
89-
$size="s"
90-
$weight="bold"
91-
$theme={isEditable ? 'greyscale' : 'warning'}
92-
>
93-
{transRole(
94-
isEditable
95-
? doc.user_role || doc.link_role
96-
: Role.READER,
97-
)}
98-
&nbsp;·&nbsp;
99-
</Text>
100-
<Text $variation="600" $size="s">
101-
{dateToDisplay}
102-
</Text>
103-
</>
104-
)}
105-
{!isDesktop && (
106-
<Text $variation="400" $size="s">
107-
{dateToDisplay}
108-
</Text>
109-
)}
65+
<DocHeaderInfo doc={doc} />
11066
</Box>
11167
</Box>
11268
{!isDeletedDoc && <DocToolBox doc={doc} />}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { t } from 'i18next';
2+
import React from 'react';
3+
4+
import { Text } from '@/components';
5+
import { useConfig } from '@/core';
6+
import { useDate } from '@/hook';
7+
import { useResponsiveStore } from '@/stores';
8+
9+
import {
10+
Doc,
11+
Role,
12+
useIsCollaborativeEditable,
13+
useTrans,
14+
} from '../../doc-management';
15+
16+
interface DocHeaderInfoProps {
17+
doc: Doc;
18+
}
19+
20+
export const DocHeaderInfo = ({ doc }: DocHeaderInfoProps) => {
21+
const { isDesktop } = useResponsiveStore();
22+
const { transRole } = useTrans();
23+
const { isEditable } = useIsCollaborativeEditable(doc);
24+
const { relativeDate, calculateDaysLeft } = useDate();
25+
const { data: config } = useConfig();
26+
27+
const childrenCount = doc.numchild ?? 0;
28+
29+
const relativeOnly = relativeDate(doc.updated_at);
30+
31+
let dateToDisplay = t('Last update: {{update}}', {
32+
update: relativeOnly,
33+
});
34+
35+
if (config?.TRASHBIN_CUTOFF_DAYS && doc.deleted_at) {
36+
const daysLeft = calculateDaysLeft(
37+
doc.deleted_at,
38+
config.TRASHBIN_CUTOFF_DAYS,
39+
);
40+
41+
dateToDisplay = `${t('Days remaining:')} ${daysLeft} ${t('days', { count: daysLeft })}`;
42+
}
43+
44+
const hasChildren = childrenCount > 0;
45+
46+
if (isDesktop) {
47+
return (
48+
<>
49+
<Text
50+
$variation="600"
51+
$size="s"
52+
$weight="bold"
53+
$theme={isEditable ? 'greyscale' : 'warning'}
54+
>
55+
{transRole(isEditable ? doc.user_role || doc.link_role : Role.READER)}
56+
&nbsp;·&nbsp;
57+
</Text>
58+
<Text $variation="600" $size="s">
59+
{dateToDisplay}
60+
</Text>
61+
</>
62+
);
63+
}
64+
65+
return (
66+
<>
67+
<Text $variation="400" $size="s">
68+
{hasChildren ? relativeOnly : dateToDisplay}
69+
</Text>
70+
{hasChildren && (
71+
<Text $variation="400" $size="s">
72+
&nbsp;•&nbsp;
73+
{t('Contains {{count}} sub-documents', {
74+
count: childrenCount,
75+
})}
76+
</Text>
77+
)}
78+
</>
79+
);
80+
};

0 commit comments

Comments
 (0)