Skip to content

Commit 49cccb1

Browse files
committed
♻️(frontend) better handling css doc states
We simplify the way we handle different doc states (deleted / readonly) in the CSS, we avoid props drilling and are more component focused.
1 parent b91840c commit 49cccb1

File tree

6 files changed

+42
-25
lines changed

6 files changed

+42
-25
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-trashbin.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ test.describe('Doc Trashbin', () => {
119119
await row.getByText(subDocName).click();
120120
await verifyDocName(page, subDocName);
121121

122+
await expect(
123+
page.locator('.--docs--doc-editor-editor-container.--docs--doc-deleted'),
124+
).toBeVisible();
125+
122126
await expect(page.getByLabel('Alert deleted document')).toBeVisible();
123127
await expect(page.getByRole('button', { name: 'Share' })).toBeDisabled();
124128
await expect(page.locator('.bn-editor')).toHaveAttribute(

src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ test.describe('Doc Visibility: Public', () => {
260260
await expect(card).toBeVisible();
261261
await expect(card.getByText('Reader')).toBeVisible();
262262

263+
await expect(
264+
otherPage.locator(
265+
'.--docs--doc-editor-editor-container.--docs--doc-readonly',
266+
),
267+
).toBeVisible();
268+
263269
const otherEditor = await getEditor({ page: otherPage });
264270
await expect(otherEditor).toHaveAttribute('contenteditable', 'false');
265271
await expect(otherEditor.getByText('Hello Public Viewonly')).toBeVisible();

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
useUploadStatus,
2929
} from '../hook';
3030
import { useEditorStore } from '../stores';
31+
import { cssEditor } from '../styles';
3132
import { DocsBlockNoteEditor } from '../types';
3233
import { randomColor } from '../utils';
3334

@@ -169,7 +170,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
169170
}, [setEditor, editor]);
170171

171172
return (
172-
<Box ref={refEditorContainer}>
173+
<Box ref={refEditorContainer} $css={cssEditor}>
173174
{errorAttachment && (
174175
<Box $margin={{ bottom: 'big', top: 'none', horizontal: 'large' }}>
175176
<TextErrors
@@ -225,12 +226,14 @@ export const BlockNoteReader = ({ initialContent }: BlockNoteReaderProps) => {
225226
useHeadings(editor);
226227

227228
return (
228-
<BlockNoteView
229-
editor={editor}
230-
editable={false}
231-
theme="light"
232-
formattingToolbar={false}
233-
slashMenu={false}
234-
/>
229+
<Box $css={cssEditor}>
230+
<BlockNoteView
231+
editor={editor}
232+
editable={false}
233+
theme="light"
234+
formattingToolbar={false}
235+
slashMenu={false}
236+
/>
237+
</Box>
235238
);
236239
};

src/frontend/apps/impress/src/features/docs/doc-editor/components/DocEditor.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import clsx from 'clsx';
12
import { useEffect } from 'react';
23
import { css } from 'styled-components';
34

@@ -12,8 +13,6 @@ import { TableContent } from '@/docs/doc-table-content/';
1213
import { useSkeletonStore } from '@/features/skeletons';
1314
import { useResponsiveStore } from '@/stores';
1415

15-
import { cssEditor } from '../styles';
16-
1716
import { BlockNoteEditor, BlockNoteReader } from './BlockNoteEditor';
1817

1918
interface DocEditorContainerProps {
@@ -55,10 +54,13 @@ export const DocEditorContainer = ({
5554
>
5655
<Box $css="flex:1;" $position="relative" $width="100%">
5756
<Box
58-
$padding={{ top: 'md' }}
57+
$padding={{ top: 'md', bottom: '2rem' }}
5958
$background="white"
60-
$css={cssEditor(readOnly, isDeletedDoc)}
61-
className="--docs--editor-container"
59+
className={clsx('--docs--doc-editor-editor-container', {
60+
'--docs--doc-readonly': readOnly,
61+
'--docs--doc-deleted': isDeletedDoc,
62+
})}
63+
$height="100%"
6264
>
6365
{docEditor}
6466
</Box>
@@ -77,7 +79,9 @@ export const DocEditor = ({ doc }: DocEditorProps) => {
7779
const { isDesktop } = useResponsiveStore();
7880
const { provider, isReady } = useProviderStore();
7981
const { isEditable, isLoading } = useIsCollaborativeEditable(doc);
80-
const readOnly = !doc.abilities.partial_update || !isEditable || isLoading;
82+
const isDeletedDoc = !!doc.deleted_at;
83+
const readOnly =
84+
!doc.abilities.partial_update || !isEditable || isLoading || isDeletedDoc;
8185
const { setIsSkeletonVisible } = useSkeletonStore();
8286
const isProviderReady = isReady && provider;
8387

@@ -117,7 +121,7 @@ export const DocEditor = ({ doc }: DocEditorProps) => {
117121
<BlockNoteEditor doc={doc} provider={provider} />
118122
)
119123
}
120-
isDeletedDoc={!!doc.deleted_at}
124+
isDeletedDoc={isDeletedDoc}
121125
readOnly={readOnly}
122126
/>
123127
</>

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/InterlinkingLinkInlineContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ const LinkSelected = ({ url, title }: LinkSelectedProps) => {
8989
background-color: ${colorsTokens['greyscale-100']};
9090
}
9191
transition: background-color 0.2s ease-in-out;
92+
93+
.--docs--doc-deleted & {
94+
pointer-events: none;
95+
}
9296
`}
9397
>
9498
{emoji ? (

src/frontend/apps/impress/src/features/docs/doc-editor/styles.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { css } from 'styled-components';
22

3-
export const cssEditor = (readonly: boolean, isDeletedDoc: boolean) => css`
3+
export const cssEditor = css`
44
&,
55
& > .bn-container,
66
& .ProseMirror {
77
height: 100%;
8-
padding-bottom: 2rem;
8+
}
99
10+
& .ProseMirror {
1011
/**
1112
* WCAG Accessibility contrast fixes for BlockNote editor
1213
*/
@@ -131,13 +132,6 @@ export const cssEditor = (readonly: boolean, isDeletedDoc: boolean) => css`
131132
.bn-block-outer:not([data-prev-depth-changed]):before {
132133
border-left: none;
133134
}
134-
135-
${isDeletedDoc &&
136-
`
137-
.node-interlinkingLinkInline button {
138-
pointer-events: none;
139-
}
140-
`}
141135
}
142136
143137
& .bn-editor {
@@ -187,8 +181,10 @@ export const cssEditor = (readonly: boolean, isDeletedDoc: boolean) => css`
187181
}
188182
189183
@media screen and (width <= 560px) {
184+
.--docs--doc-readonly & .bn-editor {
185+
padding-left: 10px;
186+
}
190187
& .bn-editor {
191-
${readonly && `padding-left: 10px;`}
192188
padding-right: 10px;
193189
}
194190
.bn-side-menu[data-block-type='heading'][data-level='1'] {

0 commit comments

Comments
 (0)