Skip to content

Commit

Permalink
Use URL origin in place of editor key for 'playground:post'
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Sep 7, 2023
1 parent 2d82c25 commit 8ad68e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
}
Expand Down Expand Up @@ -143,7 +147,7 @@ async function fetchFromUrlParams(
}
await dispatch({
type: "setOrigin",
payload: { origin: `playground:tag:${tag}` },
payload: { origin: "playground:tag" },
});
return files;
}
Expand Down
12 changes: 10 additions & 2 deletions src/integrations/editorIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type EditorIntegrationResponse = {
acknowledge: number;
};

export interface EditorIntegrationResult {
origin: string;
files: Record<string, string>;
}

export const INTEGRATION_HOOKS: Partial<EditorIntegrationHooks> = {};

// Cached return value to ensure at most one initialization
Expand All @@ -35,7 +40,7 @@ export async function setupEditorIntegration(
editorKey: string,
dispatch: (WorkplaceReducerAction) => void,
worker // MocWorker
): Promise<Record<string, string> | undefined> {
): Promise<EditorIntegrationResult | undefined> {
if (previousResult) {
return previousResult;
}
Expand Down Expand Up @@ -111,7 +116,10 @@ export async function setupEditorIntegration(

// Load a default empty project
previousResult = {
"Main.mo": "",
origin,
files: {
"Main.mo": "",
},
};
return previousResult;
}

0 comments on commit 8ad68e8

Please sign in to comment.