Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imprv: Suppresses unnecessary re-rendering within PageEditor #9629

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import styles from './EditorNavbar.module.scss';

const moduleClass = styles['editor-navbar'] ?? '';

export const EditorNavbar = (): JSX.Element => {
const EditingUsers = (): JSX.Element => {
const { data: editingUsers } = useEditingUsers();
return (
<EditingUserList
userList={editingUsers?.userList ?? []}
/>
);
};

export const EditorNavbar = (): JSX.Element => {
return (
<div className={`${moduleClass} d-flex flex-column flex-sm-row justify-content-between ps-3 ps-md-5 ps-xl-4 pe-4 py-1 align-items-sm-end`}>
<div className="order-2 order-sm-1"><PageHeader /></div>
<div className="order-1 order-sm-2"><EditingUserList
userList={editingUsers?.userList ?? []}
/>
</div>
<div className="order-1 order-sm-2"><EditingUsers /></div>
</div>
);
};
70 changes: 38 additions & 32 deletions apps/app/src/client/components/PageEditor/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Props = {
visibility?: boolean,
}

export const PageEditor = React.memo((props: Props): JSX.Element => {
export const PageEditorSubstance = (props: Props): JSX.Element => {

const { t } = useTranslation();

Expand Down Expand Up @@ -361,42 +361,48 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
return <></>;
}

return (
<div className={`flex-expand-horiz ${props.visibility ? '' : 'd-none'}`}>
<div className="page-editor-editor-container flex-expand-vert border-end">
<CodeMirrorEditorMain
isEditorMode={editorMode === EditorMode.Editor}
onSave={saveWithShortcut}
onUpload={uploadHandler}
acceptedUploadFileType={acceptedUploadFileType}
onScroll={scrollEditorHandlerThrottle}
indentSize={currentIndentSize ?? defaultIndentSize}
user={user ?? undefined}
pageId={pageId ?? undefined}
initialValue={initialValue}
editorSettings={editorSettings}
onEditorsUpdated={onEditorsUpdated}
cmProps={cmProps}
/>
</div>
<div
ref={previewRef}
onScroll={scrollPreviewHandlerThrottle}
className="page-editor-preview-container flex-expand-vert overflow-y-auto d-none d-lg-flex"
>
<Preview
rendererOptions={rendererOptions}
markdown={markdownToPreview}
pagePath={currentPagePath}
expandContentWidth={shouldExpandContent}
style={pastEndStyle}
/>
</div>
</div>
);
};

export const PageEditor = React.memo((props: Props): JSX.Element => {
return (
<div data-testid="page-editor" id="page-editor" className={`flex-expand-vert ${props.visibility ? '' : 'd-none'}`}>

<EditorNavbar />

<div className={`flex-expand-horiz ${props.visibility ? '' : 'd-none'}`}>
<div className="page-editor-editor-container flex-expand-vert border-end">
<CodeMirrorEditorMain
isEditorMode={editorMode === EditorMode.Editor}
onSave={saveWithShortcut}
onUpload={uploadHandler}
acceptedUploadFileType={acceptedUploadFileType}
onScroll={scrollEditorHandlerThrottle}
indentSize={currentIndentSize ?? defaultIndentSize}
user={user ?? undefined}
pageId={pageId ?? undefined}
initialValue={initialValue}
editorSettings={editorSettings}
onEditorsUpdated={onEditorsUpdated}
cmProps={cmProps}
/>
</div>
<div
ref={previewRef}
onScroll={scrollPreviewHandlerThrottle}
className="page-editor-preview-container flex-expand-vert overflow-y-auto d-none d-lg-flex"
>
<Preview
rendererOptions={rendererOptions}
markdown={markdownToPreview}
pagePath={currentPagePath}
expandContentWidth={shouldExpandContent}
style={pastEndStyle}
/>
</div>
</div>
<PageEditorSubstance visibility={props.visibility} />

<EditorNavbarBottom />

Expand Down
Loading