From 2f8a5bee84a90ad8c2dba45d64f5687e7a9d1601 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 6 Feb 2023 13:46:17 -0500 Subject: [PATCH] github: fixed delete repository --- src/ide/services.ts | 3 ++- src/ide/ui.ts | 31 +++++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/ide/services.ts b/src/ide/services.ts index b3729f87..236bada8 100644 --- a/src/ide/services.ts +++ b/src/ide/services.ts @@ -219,12 +219,13 @@ export class GithubService { } // check README for proper platform // unless we use githubURL= + // TODO: cannot handle multiple URLs in README const re8plat = /8bitworkshop.com[^)]+platform=([A-Za-z0-9._\-]+)/; m = re8plat.exec(readme); if (m) { console.log("platform id: '" + m[1] + "'"); if (sess.platform_id && !sess.platform_id.startsWith(m[1])) - throw Error("Platform mismatch: Repository is " + m[1] + ", you have " + this.project.platform_id + " selected."); + throw Error("Platform mismatch: Repository is " + m[1] + ", you have " + sess.platform_id + " selected."); sess.platform_id = m[1]; } // bind to repository diff --git a/src/ide/ui.ts b/src/ide/ui.ts index 4e4bdf42..f4746cb8 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -882,37 +882,32 @@ async function pushChangesToGithub(message:string) { }); } -function _deleteRepository() { +function _removeRepository() { var ghurl = getBoundGithubURL(); if (!ghurl) return; bootbox.prompt("

Are you sure you want to delete this repository (" + DOMPurify.sanitize(ghurl) + ") from browser storage?

All changes since last commit will be lost.

Type DELETE to proceed.

", (yes) => { if (yes.trim().toUpperCase() == "DELETE") { - deleteRepository(); + removeRepository(); } }); } -function deleteRepository() { +async function removeRepository() { var ghurl = getBoundGithubURL(); - var gh; setWaitDialog(true); - // delete all keys in storage - store.keys().then((keys:string[]) => { + let gh = await getGithubService(); + let sess = await gh.getGithubSession(ghurl); + gh.bind(sess, false); + // delete all keys in (repo) storage + await store.keys().then((keys:string[]) => { return Promise.all(keys.map((key) => { return store.removeItem(key); })); - }).then(() => { - gh = getGithubService(); - return gh.getGithubSession(ghurl); - }).then((sess) => { - // un-bind repo from list - gh.bind(sess, false); - }).then(() => { - setWaitDialog(false); - // leave repository - qs = {repo:'/'}; - gotoNewLocation(); }); + setWaitDialog(false); + // leave repository + qs = {repo:'/'}; + gotoNewLocation(); } function _shareEmbedLink(e) { @@ -1929,7 +1924,7 @@ function setupDebugControls() { $("#item_github_publish").click(_publishProjectToGithub); $("#item_github_push").click(_pushProjectToGithub); $("#item_github_pull").click(_pullProjectFromGithub); - $("#item_repo_delete").click(_deleteRepository); + $("#item_repo_delete").click(_removeRepository); $("#item_share_file").click(_shareEmbedLink); $("#item_reset_file").click(_revertFile); $("#item_rename_file").click(_renameFile);