From 8ad68e8bdde03428c3e57717d007a722906e8d1c Mon Sep 17 00:00:00 2001 From: rvanasa Date: Thu, 7 Sep 2023 13:16:21 -0600 Subject: [PATCH] Use URL origin in place of editor key for 'playground:post' --- src/App.tsx | 18 +++++++++++------- src/integrations/editorIntegration.ts | 12 ++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 7ad0f724..cbee7e36 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -77,11 +77,15 @@ async function fetchFromUrlParams( const tag = urlParams.get("tag"); const editorKey = urlParams.get("post"); if (editorKey) { - await dispatch({ - type: "setOrigin", - payload: { origin: `playground:post:${editorKey}` }, - }); - return setupEditorIntegration(editorKey, dispatch, worker); + const result = await setupEditorIntegration(editorKey, dispatch, worker); + if (result) { + const { origin, files } = result; + await dispatch({ + type: "setOrigin", + payload: { origin: `playground:post:${origin}` }, + }); + return files; + } } if (git) { const repo = { @@ -91,7 +95,7 @@ async function fetchFromUrlParams( }; await dispatch({ type: "setOrigin", - payload: { origin: `playground:git:${git}` }, + payload: { origin: "playground:git" }, }); return await worker.fetchGithub(repo); } @@ -143,7 +147,7 @@ async function fetchFromUrlParams( } await dispatch({ type: "setOrigin", - payload: { origin: `playground:tag:${tag}` }, + payload: { origin: "playground:tag" }, }); return files; } diff --git a/src/integrations/editorIntegration.ts b/src/integrations/editorIntegration.ts index f43ada0f..7c0799fe 100644 --- a/src/integrations/editorIntegration.ts +++ b/src/integrations/editorIntegration.ts @@ -18,6 +18,11 @@ type EditorIntegrationResponse = { acknowledge: number; }; +export interface EditorIntegrationResult { + origin: string; + files: Record; +} + export const INTEGRATION_HOOKS: Partial = {}; // Cached return value to ensure at most one initialization @@ -35,7 +40,7 @@ export async function setupEditorIntegration( editorKey: string, dispatch: (WorkplaceReducerAction) => void, worker // MocWorker -): Promise | undefined> { +): Promise { if (previousResult) { return previousResult; } @@ -111,7 +116,10 @@ export async function setupEditorIntegration( // Load a default empty project previousResult = { - "Main.mo": "", + origin, + files: { + "Main.mo": "", + }, }; return previousResult; }