diff --git a/public/workers/message_packet_worker.js b/public/workers/message_packet_worker.js index 6ff04cf..7bdf791 100644 --- a/public/workers/message_packet_worker.js +++ b/public/workers/message_packet_worker.js @@ -64,14 +64,26 @@ function GetCircularReplacerKeepDataStructure() } if (key === 'containers') { - return Object.fromEntries(value); + return [...value.entries()].map((keyPair) => { + return { + Key: keyPair[0], + Value: keyPair[1] + }; + }); } if (key === 'symbols') { - return Object.fromEntries(value); + return [...value.entries()].map((keyPair) => { + return { + Key: keyPair[0], + Value: keyPair[1] + }; + }); } - return value; + if (key === 'linkedContainers') { + return Array.from(value); + } }; } diff --git a/public/workers/message_worker.js b/public/workers/message_worker.js index ac02d3b..a5399f0 100644 --- a/public/workers/message_worker.js +++ b/public/workers/message_worker.js @@ -34,14 +34,26 @@ function GetCircularReplacerKeepDataStructure() } if (key === 'containers') { - return Object.fromEntries(value); + return [...value.entries()].map((keyPair) => { + return { + Key: keyPair[0], + Value: keyPair[1] + }; + }); } if (key === 'symbols') { - return Object.fromEntries(value); + return [...value.entries()].map((keyPair) => { + return { + Key: keyPair[0], + Value: keyPair[1] + }; + }); } - return value; + if (key === 'linkedContainers') { + return Array.from(value); + } }; } diff --git a/src/Components/API/api.ts b/src/Components/API/api.ts index 09ec2e1..e011c48 100644 --- a/src/Components/API/api.ts +++ b/src/Components/API/api.ts @@ -2,7 +2,7 @@ import { API_FETCH_URL, API_SET_CONTAINER_LIST_URL } from '../../../public/svgld import { IConfiguration } from '../../Interfaces/IConfiguration'; import { ISetContainerListRequest } from '../../Interfaces/ISetContainerListRequest'; import { ISetContainerListResponse } from '../../Interfaces/ISetContainerListResponse'; -import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload'; +import { GetCircularReplacerToDotnet } from '../../utils/saveload'; /** * Fetch the configuration from the API @@ -36,7 +36,7 @@ export async function FetchConfiguration(): Promise { export async function SetContainerList(request: ISetContainerListRequest): Promise { const url = API_SET_CONTAINER_LIST_URL; - const dataParsed = JSON.stringify(request, GetCircularReplacerKeepDataStructure()); + const dataParsed = JSON.stringify(request, GetCircularReplacerToDotnet()); // The test library cannot use the Fetch API // @ts-expect-error // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions diff --git a/src/Components/Messages/Messages.tsx b/src/Components/Messages/Messages.tsx index 139a123..9e04670 100644 --- a/src/Components/Messages/Messages.tsx +++ b/src/Components/Messages/Messages.tsx @@ -5,7 +5,7 @@ import { MessageType } from '../../Enums/MessageType'; import { IHistoryState } from '../../Interfaces/IHistoryState'; import { IMessage } from '../../Interfaces/IMessage'; import { DISABLE_API } from '../../utils/default'; -import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload'; +import { GetCircularReplacerToDotnet } from '../../utils/saveload'; import { TITLE_BAR_HEIGHT } from '../Sidebar/Sidebar'; interface IMessagesProps { diff --git a/src/Components/UI/UseWorker.tsx b/src/Components/UI/UseWorker.tsx index 7f8a904..ed6b8e2 100644 --- a/src/Components/UI/UseWorker.tsx +++ b/src/Components/UI/UseWorker.tsx @@ -3,7 +3,7 @@ import { IHistoryState } from '../../Interfaces/IHistoryState'; import { IGetFeedbackRequest } from '../../Interfaces/IGetFeedbackRequest'; import { IGetFeedbackResponse } from '../../Interfaces/IGetFeedbackResponse'; import { IMessage } from '../../Interfaces/IMessage'; -import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload'; +import { GetCircularReplacerToDotnet } from '../../utils/saveload'; import { API_GET_FEEDBACK_URL } from '../../../public/svgld-settings'; // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions @@ -37,7 +37,7 @@ export function UseAsync( // eslint-disable-next-line @typescript-eslint/naming-convention ApplicationState: state }; - const dataParsed = JSON.stringify(request, GetCircularReplacerKeepDataStructure()); + const dataParsed = JSON.stringify(request, GetCircularReplacerToDotnet()); fetch(API_GET_FEEDBACK_URL, { method: 'POST', headers: new Headers({ diff --git a/src/main.tsx b/src/main.tsx index 21c0771..58b8818 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -16,6 +16,9 @@ function RenderRoot(root: Element | Document): void { namespace SVGLayoutDesigner { // eslint-disable-next-line @typescript-eslint/naming-convention export const Render = RenderRoot; + export const API_FETCH_URL = 'http://localhost:5000'; + export const API_SET_CONTAINER_LIST_URL = 'http://localhost:5000/SetContainerList'; + export const API_GET_FEEDBACK_URL = 'http://localhost:5000/GetFeedback'; } (window as any).SVGLayoutDesigner = SVGLayoutDesigner; diff --git a/src/utils/saveload.ts b/src/utils/saveload.ts index abdbbd1..7250500 100644 --- a/src/utils/saveload.ts +++ b/src/utils/saveload.ts @@ -77,18 +77,32 @@ export function GetCircularReplacer(): (key: any, value: object | Map | null) => object | null | undefined { +export function GetCircularReplacerToDotnet(): (key: any, value: object | Map | null) => object | null | undefined { return (key: any, value: object | null) => { if (key === 'parent') { return; } if (key === 'containers') { - return Object.fromEntries(value as Map); + return [...(value as Map).entries()].map((keyPair: [string, any]) => { + return { + Key: keyPair[0], + Value: keyPair[1] + }; + }); } if (key === 'symbols') { - return Object.fromEntries((value as Map)); + return [...(value as Map).entries()].map((keyPair: [string, any]) => { + return { + Key: keyPair[0], + Value: keyPair[1] + }; + }); + } + + if (key === 'linkedContainers') { + return Array.from(value as Set); } return value;