Skip to content

Commit 6ca654b

Browse files
committed
🚸(frontend) let loader until resource ready
The backend can analyze the upload file, this take time, so we need to show a loader until the backend finish the analysis.
1 parent 0745853 commit 6ca654b

File tree

10 files changed

+310
-9
lines changed

10 files changed

+310
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to
1818
- ✨(backend) integrate maleware_detection from django-lasuite #936
1919
- 🩺(CI) add lint spell mistakes #954
2020
- 🛂(frontend) block edition to not connected users #945
21+
- 🚸 Let loader during upload analyze #984
2122

2223
### Changed
2324

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ test.describe('Doc Editor', () => {
425425
const downloadPromise = page.waitForEvent('download', (download) => {
426426
return download.suggestedFilename().includes(`html`);
427427
});
428+
const responseCheckPromise = page.waitForResponse(
429+
(response) =>
430+
response.url().includes('media-check') && response.status() === 200,
431+
);
428432

429433
await verifyDocName(page, randomDoc);
430434

@@ -439,6 +443,8 @@ test.describe('Doc Editor', () => {
439443
const fileChooser = await fileChooserPromise;
440444
await fileChooser.setFiles(path.join(__dirname, 'assets/test.html'));
441445

446+
await responseCheckPromise;
447+
442448
await page.locator('.bn-block-content[data-name="test.html"]').click();
443449
await page.getByRole('button', { name: 'Download file' }).click();
444450

@@ -455,6 +461,51 @@ test.describe('Doc Editor', () => {
455461
expect(svgBuffer.toString()).toContain('Hello svg');
456462
});
457463

464+
test('it analyzes uploads', async ({ page, browserName }) => {
465+
const [randomDoc] = await createDoc(page, 'doc-editor', browserName, 1);
466+
467+
let requestCount = 0;
468+
await page.route(
469+
/.*\/documents\/.*\/media-check\/\?key=.*/,
470+
async (route) => {
471+
const request = route.request();
472+
if (request.method().includes('GET')) {
473+
await route.fulfill({
474+
json: {
475+
status: requestCount ? 'ready' : 'processing',
476+
file: '/anything.html',
477+
},
478+
});
479+
480+
requestCount++;
481+
} else {
482+
await route.continue();
483+
}
484+
},
485+
);
486+
487+
const fileChooserPromise = page.waitForEvent('filechooser');
488+
489+
await verifyDocName(page, randomDoc);
490+
491+
const editor = page.locator('.ProseMirror.bn-editor');
492+
493+
await editor.click();
494+
await editor.locator('.bn-block-outer').last().fill('/');
495+
await page.getByText('Embedded file').click();
496+
await page.getByText('Upload file').click();
497+
498+
const fileChooser = await fileChooserPromise;
499+
await fileChooser.setFiles(path.join(__dirname, 'assets/test.html'));
500+
501+
await expect(editor.getByText('Analyzing file...')).toBeVisible();
502+
// The retry takes a few seconds
503+
await expect(editor.getByText('test.html')).toBeVisible({
504+
timeout: 7000,
505+
});
506+
await expect(editor.getByText('Analyzing file...')).toBeHidden();
507+
});
508+
458509
test('it checks block editing when not connected to collab server', async ({
459510
page,
460511
}) => {

src/frontend/apps/impress/src/custom-next.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ declare module '*.svg' {
1313
}
1414

1515
declare module '*.svg?url' {
16-
const content: string;
16+
const content: {
17+
src: string;
18+
width: number;
19+
height: number;
20+
blurWidth: number;
21+
blurHeight: number;
22+
};
1723
export default content;
1824
}
1925

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { APIError, errorCauses } from '@/api';
2+
3+
interface CheckDocMediaStatusResponse {
4+
file?: string;
5+
status: 'processing' | 'ready';
6+
}
7+
8+
interface CheckDocMediaStatus {
9+
urlMedia: string;
10+
}
11+
12+
export const checkDocMediaStatus = async ({
13+
urlMedia,
14+
}: CheckDocMediaStatus): Promise<CheckDocMediaStatusResponse> => {
15+
const response = await fetch(urlMedia, {
16+
credentials: 'include',
17+
});
18+
19+
if (!response.ok) {
20+
throw new APIError(
21+
'Failed to check the media status',
22+
await errorCauses(response),
23+
);
24+
}
25+
26+
return response.json() as Promise<CheckDocMediaStatusResponse>;
27+
};
Lines changed: 27 additions & 0 deletions
Loading
Lines changed: 17 additions & 0 deletions
Loading

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { Box, TextErrors } from '@/components';
1818
import { Doc, useIsCollaborativeEditable } from '@/docs/doc-management';
1919
import { useAuth } from '@/features/auth';
2020

21-
import { useUploadFile } from '../hook';
22-
import { useHeadings } from '../hook/useHeadings';
21+
import { useHeadings, useUploadFile, useUploadStatus } from '../hook/';
2322
import useSaveDoc from '../hook/useSaveDoc';
2423
import { useEditorStore } from '../stores';
2524
import { cssEditor } from '../styles';
25+
import { DocsBlockNoteEditor } from '../types';
2626
import { randomColor } from '../utils';
2727

2828
import { BlockNoteSuggestionMenu } from './BlockNoteSuggestionMenu';
@@ -63,7 +63,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
6363
: user?.full_name || user?.email || t('Anonymous');
6464
const showCursorLabels: 'always' | 'activity' | (string & {}) = 'activity';
6565

66-
const editor = useCreateBlockNote(
66+
const editor: DocsBlockNoteEditor = useCreateBlockNote(
6767
{
6868
codeBlock,
6969
collaboration: {
@@ -127,7 +127,9 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
127127
},
128128
[collabName, lang, provider, uploadFile],
129129
);
130+
130131
useHeadings(editor);
132+
useUploadStatus(editor);
131133

132134
useEffect(() => {
133135
setEditor(editor);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const ModalConfirmDownloadUnsafe = ({
3232
aria-label={t('Download')}
3333
color="danger"
3434
onClick={() => {
35-
console.log('onClick');
3635
if (onConfirm) {
3736
void onConfirm();
3837
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './useHeadings';
12
export * from './useSaveDoc';
23
export * from './useUploadFile';

0 commit comments

Comments
 (0)