Web: Doceditor: refactoring

This commit is contained in:
Artem Tarasov 2022-03-25 14:49:45 +03:00
parent f164df47c0
commit c8d1a6dda2
2 changed files with 30 additions and 8 deletions

View File

@ -70,7 +70,7 @@ export const useDynamicScript = (args) => {
}; };
}; };
const DynamicComponent = React.memo(({ system, ...rest }) => { const DynamicComponent = ({ system, ...rest }) => {
const [isInitialized, setIsInitialized] = React.useState(false); const [isInitialized, setIsInitialized] = React.useState(false);
const [LoadedComponent, setLoadedComponent] = React.useState(); const [LoadedComponent, setLoadedComponent] = React.useState();
@ -95,11 +95,12 @@ const DynamicComponent = React.memo(({ system, ...rest }) => {
throw Error("failed"); throw Error("failed");
} }
// console.log("dynamic", rest);
if (ready && !isInitialized) { if (ready && !isInitialized) {
//console.log("dynamic 2", rest);
setIsInitialized(true); setIsInitialized(true);
const Component = React.lazy( const Component = React.lazy(loadComponent(system.scope, system.module));
loadComponent(system.scope, system.module, system?.name)
);
setLoadedComponent(Component); setLoadedComponent(Component);
} }
@ -109,6 +110,6 @@ const DynamicComponent = React.memo(({ system, ...rest }) => {
<LoadedComponent {...rest} /> <LoadedComponent {...rest} />
</React.Suspense> </React.Suspense>
); );
}); };
export default DynamicComponent; export default DynamicComponent;

View File

@ -24,7 +24,7 @@ const withDialogs = (WrappedComponent) => {
const [extension, setExtension] = useState(); const [extension, setExtension] = useState();
const [openNewTab, setNewOpenTab] = useState(false); const [openNewTab, setNewOpenTab] = useState(false);
const { t } = useTranslation(); const { t } = useTranslation(["Editor", "Common"]);
const { fileInfo, fileId, mfReady } = props; const { fileInfo, fileId, mfReady } = props;
@ -61,6 +61,7 @@ const withDialogs = (WrappedComponent) => {
}; };
const onSDKRequestInsertImage = (event) => { const onSDKRequestInsertImage = (event) => {
console.log("onSDKRequestInsertImage", event.data, insertImageAction);
setTypeInsertImageAction(event.data); setTypeInsertImageAction(event.data);
setFilesType(insertImageAction); setFilesType(insertImageAction);
setIsFileDialogVisible(true); setIsFileDialogVisible(true);
@ -110,13 +111,32 @@ const withDialogs = (WrappedComponent) => {
}; };
const fileTypeDetection = () => { const fileTypeDetection = () => {
// console.log(
// "------",
// insertImageAction,
// filesType,
// insertImageActionProps,
// "--------"
// );
if (filesType === insertImageAction) { if (filesType === insertImageAction) {
// console.log(
// "filesType === insertImageAction",
// filesType === insertImageAction
// );
return insertImageActionProps; return insertImageActionProps;
} }
if (filesType === mailMergeAction) { if (filesType === mailMergeAction) {
// console.log(
// "filesType === mailMergeAction",
// filesType === mailMergeAction
// );
return mailMergeActionProps; return mailMergeActionProps;
} }
if (filesType === compareFilesAction) { if (filesType === compareFilesAction) {
// console.log(
// "filesType === compareFilesAction",
// filesType === compareFilesAction
// );
return compareFilesActionProps; return compareFilesActionProps;
} }
}; };
@ -222,7 +242,8 @@ const withDialogs = (WrappedComponent) => {
/> />
); );
const fileType = fileTypeDetection(); const typeFilter = fileTypeDetection();
// console.log(typeFilter, "-----------------");
const selectFileDialog = mfReady && ( const selectFileDialog = mfReady && (
<DynamicComponent <DynamicComponent
@ -236,7 +257,7 @@ const withDialogs = (WrappedComponent) => {
isPanelVisible={isFileDialogVisible} isPanelVisible={isFileDialogVisible}
onSelectFile={onSelectFile} onSelectFile={onSelectFile}
onClose={onCloseFileDialog} onClose={onCloseFileDialog}
{...fileType} {...typeFilter}
titleFilesList={selectFilesListTitle()} titleFilesList={selectFilesListTitle()}
headerName={t("SelectFileTitle")} headerName={t("SelectFileTitle")}
/> />