wisemapping-frontend/packages/webapp/src/components/editor-page/index.tsx

54 lines
1.9 KiB
TypeScript
Raw Normal View History

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-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';
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';
import { activeInstance } from '../../redux/clientSlice';
import { PersistenceManager } from '@wisemapping/mindplot';
2022-01-25 19:10:40 +01:00
export type EditorPropsType = {
mapId: number;
2022-02-06 20:12:20 +01:00
isTryMode: boolean;
2022-01-25 19:10:40 +01:00
};
2022-02-06 00:09:43 +01:00
const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement => {
2022-01-25 19:10:40 +01:00
const [activeDialog, setActiveDialog] = React.useState<ActionType | null>(null);
2022-02-13 04:15:51 +01:00
const hotkeys = 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);
const [persistenceManager, setPersistenceManager] = React.useState<PersistenceManager>();
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-21 03:50:03 +01:00
const persistence = client.buildPersistenceManager();
setPersistenceManager(persistence);
return () => client.removePersistenceManager();
2022-02-16 05:39:52 +01:00
}, []);
2022-02-21 03:50:03 +01:00
if (!persistenceManager) {
// persistenceManager must be ready for the editor to work
return null;
}
2022-01-25 19:10:40 +01:00
return <>
2022-02-21 03:50:03 +01:00
<Editor {...props} onAction={setActiveDialog}
locale={userLocale.code} hotkeys={hotkeys}
persistenceManager={persistenceManager} />
2022-01-25 19:10:40 +01:00
{
2022-02-05 22:53:10 +01:00
activeDialog &&
2022-01-25 19:10:40 +01:00
<ActionDispatcher
action={activeDialog}
onClose={() => setActiveDialog(null)}
mapsId={[mapId]}
fromEditor
/>
}
</>
}
2022-02-06 00:09:43 +01:00
export default EditorPage;