From fbd8456753e393e5f11f2d68b3c80aec2eaf64de Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Thu, 19 Sep 2024 10:39:54 -0700 Subject: [PATCH 1/2] no spurious error on asset editor response --- localtypings/pxteditor.d.ts | 1 + webapp/src/assetEditor.tsx | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/localtypings/pxteditor.d.ts b/localtypings/pxteditor.d.ts index 7ba3c537a68e..42ac5e4b9180 100644 --- a/localtypings/pxteditor.d.ts +++ b/localtypings/pxteditor.d.ts @@ -1296,6 +1296,7 @@ declare namespace pxt.editor { interface BaseAssetEditorResponse { id?: number; + success: boolean; } interface OpenAssetEditorResponse extends BaseAssetEditorResponse { diff --git a/webapp/src/assetEditor.tsx b/webapp/src/assetEditor.tsx index 6deb11e92326..e7b0d1fea35b 100644 --- a/webapp/src/assetEditor.tsx +++ b/webapp/src/assetEditor.tsx @@ -58,7 +58,8 @@ export class AssetEditor extends React.Component<{}, AssetEditorState> { this.sendResponse({ id: request.id, - type: request.type + type: request.type, + success: true }); break; case "open": @@ -73,7 +74,8 @@ export class AssetEditor extends React.Component<{}, AssetEditorState> { }); this.sendResponse({ id: request.id, - type: request.type + type: request.type, + success: true }); break; case "duplicate": @@ -85,14 +87,16 @@ export class AssetEditor extends React.Component<{}, AssetEditorState> { }); this.sendResponse({ id: request.id, - type: request.type + type: request.type, + success: true, }); break; case "save": this.sendResponse({ id: request.id, type: request.type, - files: this.saveProjectFiles() + files: this.saveProjectFiles(), + success: true }); break; } From c4fd26ced6e60dc6a9b720d7db19f0cfcf68f73e Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Thu, 19 Sep 2024 10:49:55 -0700 Subject: [PATCH 2/2] fix up types --- localtypings/pxteditor.d.ts | 7 +++++++ pxtservices/iframeDriver.ts | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/localtypings/pxteditor.d.ts b/localtypings/pxteditor.d.ts index 42ac5e4b9180..e71924644bb8 100644 --- a/localtypings/pxteditor.d.ts +++ b/localtypings/pxteditor.d.ts @@ -1296,7 +1296,14 @@ declare namespace pxt.editor { interface BaseAssetEditorResponse { id?: number; + /** + * indicate if operation started or completed successfully + */ success: boolean; + /** + * Error object if any + */ + error?: any; } interface OpenAssetEditorResponse extends BaseAssetEditorResponse { diff --git a/pxtservices/iframeDriver.ts b/pxtservices/iframeDriver.ts index bef798c45622..f4fe919d6d2f 100644 --- a/pxtservices/iframeDriver.ts +++ b/pxtservices/iframeDriver.ts @@ -98,9 +98,9 @@ export abstract class IframeDriver { } protected resolvePendingMessage(event: MessageEvent) { - const data = event.data as pxt.editor.EditorMessageResponse; - if (data.id && this.pendingMessages[data.id]) { - const resp = event.data as pxt.editor.EditorMessageResponse; + const resp = event.data as pxt.editor.EditorMessageResponse | pxt.editor.AssetEditorResponse; + + if (resp.id && this.pendingMessages[resp.id]) { const pending = this.pendingMessages[resp.id!]; delete this.pendingMessages[resp.id!];