2022-02-16 05:39:52 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2022-02-06 00:09:43 +01:00
|
|
|
import ActionDispatcher from '../maps-page/action-dispatcher';
|
|
|
|
import { ActionType } from '../maps-page/action-chooser';
|
2022-02-06 20:12:20 +01:00
|
|
|
import Editor from '@wisemapping/editor';
|
2022-03-05 17:10:03 +01:00
|
|
|
import { EditorRenderMode, PersistenceManager } from '@wisemapping/mindplot';
|
|
|
|
|
2022-02-06 00:09:43 +01:00
|
|
|
import AppI18n from '../../classes/app-i18n';
|
2022-02-13 04:15:51 +01:00
|
|
|
import { useSelector } from 'react-redux';
|
2022-02-22 06:55:13 +01:00
|
|
|
import { hotkeysEnabled } from '../../redux/editorSlice';
|
2022-02-16 05:39:52 +01:00
|
|
|
import ReactGA from 'react-ga';
|
2022-02-21 03:50:03 +01:00
|
|
|
import Client from '../../classes/client';
|
2022-03-05 17:10:03 +01:00
|
|
|
import { activeInstance, fetchAccount, fetchMapById } from '../../redux/clientSlice';
|
2022-02-22 19:43:16 +01:00
|
|
|
import EditorOptionsBulder from './EditorOptionsBuider';
|
2022-01-25 19:10:40 +01:00
|
|
|
|
|
|
|
export type EditorPropsType = {
|
2022-02-06 20:12:20 +01:00
|
|
|
isTryMode: boolean;
|
2022-01-25 19:10:40 +01:00
|
|
|
};
|
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
const EditorPage = ({ isTryMode }: EditorPropsType): React.ReactElement => {
|
2022-01-25 19:10:40 +01:00
|
|
|
const [activeDialog, setActiveDialog] = React.useState<ActionType | null>(null);
|
2022-02-22 06:55:13 +01:00
|
|
|
const hotkey = useSelector(hotkeysEnabled);
|
2022-02-10 01:36:31 +01:00
|
|
|
const userLocale = AppI18n.getUserLocale();
|
2022-02-21 03:50:03 +01:00
|
|
|
const client: Client = useSelector(activeInstance);
|
2022-02-05 22:53:10 +01:00
|
|
|
|
2022-02-16 05:39:52 +01:00
|
|
|
useEffect(() => {
|
|
|
|
ReactGA.pageview(window.location.pathname + window.location.search);
|
|
|
|
}, []);
|
2022-02-22 06:37:00 +01:00
|
|
|
|
2022-03-05 17:10:03 +01:00
|
|
|
const findEditorMode = (isTryMode: boolean, mapId: number): EditorRenderMode | null => {
|
|
|
|
let result: EditorRenderMode = null;
|
|
|
|
if (isTryMode) {
|
|
|
|
result = 'showcase';
|
|
|
|
} else if (global.mindmapLocked) {
|
|
|
|
result = 'viewonly';
|
|
|
|
} else {
|
|
|
|
const fetchResult = fetchMapById(mapId);
|
|
|
|
if (!fetchResult.isLoading) {
|
|
|
|
if (fetchResult.error) {
|
2022-03-08 03:37:30 +01:00
|
|
|
throw new Error(`User could not be loaded: ${JSON.stringify(fetchResult.error)} - ${fetchResult.error}`);
|
2022-03-05 17:10:03 +01:00
|
|
|
}
|
2022-03-07 16:35:08 +01:00
|
|
|
result = fetchResult?.map?.role === 'owner' ? 'edition-owner' : 'edition-editor';
|
2022-03-05 17:10:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// What is the role ?
|
|
|
|
const mapId = EditorOptionsBulder.loadMapId();
|
|
|
|
const mode = findEditorMode(isTryMode, mapId);
|
|
|
|
|
2022-02-26 04:59:21 +01:00
|
|
|
// Account settings can be null and editor cannot be initilized multiple times. This creates problems
|
|
|
|
// at the i18n resource loading.
|
2022-03-05 17:10:03 +01:00
|
|
|
const isAccountLoaded = mode === 'showcase' || fetchAccount;
|
|
|
|
const loadCompleted = mode && isAccountLoaded;
|
|
|
|
|
|
|
|
let options, persistence: PersistenceManager;
|
|
|
|
if (loadCompleted) {
|
|
|
|
options = EditorOptionsBulder.build(userLocale.code, mode, hotkey);
|
|
|
|
persistence = client.buildPersistenceManager(mode);
|
|
|
|
}
|
2022-02-26 04:59:21 +01:00
|
|
|
|
|
|
|
return loadCompleted ? (
|
2022-02-22 06:37:00 +01:00
|
|
|
<>
|
|
|
|
<Editor onAction={setActiveDialog}
|
|
|
|
options={options}
|
2022-02-26 04:59:21 +01:00
|
|
|
persistenceManager={persistence}
|
2022-02-22 06:37:00 +01:00
|
|
|
mapId={mapId} />
|
|
|
|
{
|
|
|
|
activeDialog &&
|
|
|
|
<ActionDispatcher
|
|
|
|
action={activeDialog}
|
|
|
|
onClose={() => setActiveDialog(null)}
|
|
|
|
mapsId={[mapId]}
|
|
|
|
fromEditor
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</>) : <></>
|
2022-01-25 19:10:40 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
|
2022-02-06 00:09:43 +01:00
|
|
|
export default EditorPage;
|
|
|
|
|