wisemapping-frontend/packages/webapp/src/components/editor-page/PersistenceManagerUtils.ts

25 lines
872 B
TypeScript
Raw Normal View History

import AppConfig from '../../classes/app-config';
2023-01-05 01:48:01 +01:00
import { LocalStorageManager, Mindmap, XMLSerializerFactory } from '@wisemapping/editor';
2022-11-22 04:37:16 +01:00
export const fetchMindmap = async (mapId: number): Promise<Mindmap> => {
let mindmap: Mindmap;
if (AppConfig.isRestClient()) {
const persistence = new LocalStorageManager(`/c/restful/maps/{id}/document/xml`, true);
2022-11-22 04:37:16 +01:00
mindmap = await persistence.load(String(mapId));
} else {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(
`
<map name="${mapId}" version="tango">
<topic central="true" text="This is the map ${mapId}" id="1" fontStyle=";;#ffffff;;;"></topic>
</map>
`,
'text/xml',
);
const serializer = XMLSerializerFactory.getSerializer('tango');
2022-11-22 04:37:16 +01:00
mindmap = Promise.resolve(serializer.loadFromDom(xmlDoc, String(mapId)));
}
return mindmap;
};