1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-03 08:35:29 +02:00

Chore: Desktop: Fix NoteEditor unnecessary rerendering (#8662)

This commit is contained in:
Henry Heino 2023-08-14 10:33:48 -07:00 committed by GitHub
parent 357c23b588
commit c50052ac04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import * as React from 'react';
import { useState, useEffect, useCallback, useRef } from 'react';
import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
import TinyMCE from './NoteBody/TinyMCE/TinyMCE';
import CodeMirror from './NoteBody/CodeMirror/CodeMirror';
import { connect } from 'react-redux';
@ -40,7 +40,7 @@ import Note from '@joplin/lib/models/Note';
import Folder from '@joplin/lib/models/Folder';
const bridge = require('@electron/remote').require('./bridge').default;
import NoteRevisionViewer from '../NoteRevisionViewer';
import { readFromSettings } from '@joplin/lib/services/share/reducer';
import { parseShareCache } from '@joplin/lib/services/share/reducer';
import useAsyncEffect from '@joplin/lib/hooks/useAsyncEffect';
import { ModelType } from '@joplin/lib/BaseModel';
import BaseItem from '@joplin/lib/models/BaseItem';
@ -286,11 +286,15 @@ function NoteEditor(props: NoteEditorProps) {
// }
// }, [props.dispatch]);
const shareCache = useMemo(() => {
return parseShareCache(props.shareCacheSetting);
}, [props.shareCacheSetting]);
useAsyncEffect(async event => {
if (!formNote.id) return;
try {
const result = await itemIsReadOnly(BaseItem, ModelType.Note, ItemChange.SOURCE_UNSPECIFIED, formNote.id, props.syncUserId, props.shareCache);
const result = await itemIsReadOnly(BaseItem, ModelType.Note, ItemChange.SOURCE_UNSPECIFIED, formNote.id, props.syncUserId, shareCache);
if (event.cancelled) return;
setIsReadOnly(result);
} catch (error) {
@ -301,7 +305,7 @@ function NoteEditor(props: NoteEditorProps) {
throw error;
}
}
}, [formNote.id, props.syncUserId, props.shareCache]);
}, [formNote.id, props.syncUserId, shareCache]);
const onBodyWillChange = useCallback((event: any) => {
handleProvisionalFlag();
@ -656,7 +660,7 @@ const mapStateToProps = (state: AppState) => {
isSafeMode: state.settings.isSafeMode,
useCustomPdfViewer: false,
syncUserId: state.settings['sync.userId'],
shareCache: readFromSettings(state),
shareCacheSetting: state.settings['sync.shareCache'],
};
};

View File

@ -2,7 +2,6 @@
import AsyncActionQueue from '@joplin/lib/AsyncActionQueue';
import { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils';
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
import { State as ShareState } from '@joplin/lib/services/share/reducer';
import { MarkupLanguage } from '@joplin/renderer';
import { RenderResult, RenderResultPluginAsset } from '@joplin/renderer/MarkupToHtml';
import { MarkupToHtmlOptions } from './useMarkupToHtml';
@ -46,7 +45,7 @@ export interface NoteEditorProps {
contentMaxWidth: number;
isSafeMode: boolean;
useCustomPdfViewer: boolean;
shareCache: ShareState;
shareCacheSetting: string;
syncUserId: string;
}

View File

@ -82,10 +82,6 @@ export const parseShareCache = (serialized: string): State => {
};
};
export const readFromSettings = (state: RootState): State => {
return parseShareCache(state.settings['sync.shareCache']);
};
export function isSharedFolderOwner(state: RootState, folderId: string): boolean {
const userId = state.settings['sync.userId'];
const share = state[stateRootKey].shares.find(s => s.folder_id === folderId);