From 312e5e0745c54b72b8b0141b8db1b69f5319afe8 Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Thu, 10 Nov 2022 12:15:21 -0800 Subject: [PATCH] don't duplicate persistent share links when importing --- webapp/src/app.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/webapp/src/app.tsx b/webapp/src/app.tsx index f27249643ed8..b5eafcce47c8 100644 --- a/webapp/src/app.tsx +++ b/webapp/src/app.tsx @@ -5387,9 +5387,18 @@ async function importGithubProject(repoid: string, requireSignin?: boolean) { function loadHeaderBySharedId(id: string) { core.showLoading("loadingheader", lf("loading project...")); + let previousHeader: pxt.workspace.Header; + if (id.startsWith("S") && auth.hasIdentity() && data.getData(auth.LOGGED_IN)) { + // if loading a persistent url, check for existing headers + previousHeader = workspace.getHeaders().find(h => h.pubPermalink === id); + } + + const projHeaderPromise = previousHeader + ? Promise.resolve(previousHeader) + : workspace.installByIdAsync(id); - workspace.installByIdAsync(id) - .then(hd => theEditor.loadHeaderAsync(hd, null)) + projHeaderPromise + .then(hd => theEditor.loadHeaderAsync(hd, null, !!previousHeader)) .catch(e => { theEditor.openHome(); core.handleNetworkError(e);