Simplefy editor modes

This commit is contained in:
Paulo Gustavo Veiga 2022-02-06 11:12:20 -08:00
parent 62024393e9
commit 560429116a
4 changed files with 83 additions and 105 deletions

View File

@ -31,14 +31,12 @@ import ActionButton from '../action-button';
export type ToolbarActionType = 'export' | 'publish' | 'history' | 'print' | 'share';
export type ToolbarPropsType = {
memoryPersistence: boolean;
readOnlyMode: boolean;
isTryMode: boolean;
onAction: (action: ToolbarActionType) => void;
};
export default function Toolbar({
memoryPersistence,
readOnlyMode,
isTryMode: isTryMode,
onAction,
}: ToolbarPropsType): React.ReactElement {
const intl = useIntl();
@ -48,15 +46,13 @@ export default function Toolbar({
<div id="backToList">
<img src={BackIconSvg} />
</div>
{!memoryPersistence && (
{!isTryMode && (
<div id="persist" className="buttonContainer">
<ToolbarButton id="save" className="buttonOn">
<img src={SaveSvg} />
</ToolbarButton>
</div>
)}
{!readOnlyMode && (
<>
<div id="edit" className="buttonContainer">
<ToolbarButton id="undoEdition" className="buttonOn">
<img src={UndoSvg} />
@ -114,9 +110,7 @@ export default function Toolbar({
</ToolbarButton>
</div>
<div id="separator" className="buttonContainer"></div>
</>
)}
{!memoryPersistence && (
{!isTryMode && (
<ToolbarRightContainer>
<ToolbarButton
id="export"

View File

@ -38,14 +38,14 @@ declare global {
export type EditorPropsType = {
initCallback?: () => void;
mapId: number;
memoryPersistence: boolean;
mapId?: number;
isTryMode: boolean;
readOnlyMode: boolean;
locale?: string;
onAction: (action: ToolbarActionType) => void;
};
function loadLocaleData(locale: string) {
const loadLocaleData = (locale: string) => {
switch (locale) {
case 'fr':
return FR;
@ -65,7 +65,7 @@ const initMindplot = () => {
document.title = `${global.mapTitle} | WiseMapping `;
// Configure persistence manager ...
let persistence;
let persistence: PersistenceManager;
if (!global.memoryPersistence && !global.readOnly) {
persistence = new RESTPersistenceManager({
documentUrl: '/c/restful/maps/{id}/document',
@ -111,38 +111,26 @@ const initMindplot = () => {
}
};
export default function Editor({
const Editor = ({
initCallback = initMindplot,
mapId,
memoryPersistence,
readOnlyMode,
isTryMode: isTryMode,
locale = 'en',
onAction,
}: EditorPropsType): React.ReactElement {
const [localeTranslation, setLocaleTranslation] = React.useState(null);
}: EditorPropsType): React.ReactElement => {
React.useEffect(() => {
if (localeTranslation && !global.designer) {
initCallback();
}
}, [localeTranslation]);
React.useEffect(() => {
const loadAndSetLocale = async () => {
setLocaleTranslation(await loadLocaleData(locale));
};
loadAndSetLocale();
}, [locale])
if (!localeTranslation) {
return null;
}
}, []);
return (
<IntlProvider locale={locale} defaultLocale="en" messages={localeTranslation}>
<IntlProvider locale={locale} defaultLocale="en" messages={loadLocaleData(locale)}>
<Toolbar
memoryPersistence={memoryPersistence}
readOnlyMode={readOnlyMode}
isTryMode={isTryMode}
onAction={onAction}
/>
<div id="mindplot"></div>
<Footer showTryPanel={memoryPersistence} />
<Footer showTryPanel={isTryMode} />
</IntlProvider>
);
}
export default Editor;

View File

@ -41,8 +41,7 @@ const App = (): ReactElement => {
const locale = appi18n.getBrowserLocale();
// global variables set server-side
const memoryPersistence = global.memoryPersistence;
const readOnlyMode = global.readOnly;
const istTryMode = global.memoryPersistence;
const mapId = parseInt(global.mapId, 10);
return locale.message ? (
@ -85,12 +84,10 @@ const App = (): ReactElement => {
component={MapsPage}
/>
<Route exact path="/c/maps/:id/edit">
<EditorPage memoryPersistence={memoryPersistence}
readOnlyMode={readOnlyMode} mapId={mapId} />
<EditorPage isTryMode={istTryMode} mapId={mapId} />
</Route>
<Route exact path="/c/maps/:id/try">
<EditorPage memoryPersistence={memoryPersistence}
readOnlyMode={readOnlyMode} mapId={mapId} />
<EditorPage isTryMode={istTryMode} mapId={mapId} />
</Route>
</Switch>
</Router>

View File

@ -1,13 +1,12 @@
import React from 'react';
import ActionDispatcher from '../maps-page/action-dispatcher';
import { ActionType } from '../maps-page/action-chooser';
import WiseEditor from '@wisemapping/editor';
import Editor from '@wisemapping/editor';
import AppI18n from '../../classes/app-i18n';
export type EditorPropsType = {
mapId: number;
memoryPersistence: boolean;
readOnlyMode: boolean;
isTryMode: boolean;
};
const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement => {
@ -18,7 +17,7 @@ const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement =>
const userLocale = appi18n.getUserLocale();
return <>
<WiseEditor {...props} onAction={setActiveDialog} locale={userLocale.code} />
<Editor {...props} onAction={setActiveDialog} locale={userLocale.code} />
{
activeDialog &&
<ActionDispatcher