diff options
author | 2021-07-08 19:31:59 +0700 | |
---|---|---|
committer | 2021-07-08 19:31:59 +0700 | |
commit | f908677216e84f4a238a69f0573a257945ea6a25 (patch) | |
tree | 62e5c6a111db006fb1afccc0889169cd1dce6d2b /source/features/quick-repo-deletion.tsx | |
parent | 0830ef295133f99d66727c85af4bef1f252c1461 (diff) | |
download | refined-github-f908677216e84f4a238a69f0573a257945ea6a25.tar.gz refined-github-f908677216e84f4a238a69f0573a257945ea6a25.tar.zst refined-github-f908677216e84f4a238a69f0573a257945ea6a25.zip |
Lint (#4544)
Diffstat (limited to 'source/features/quick-repo-deletion.tsx')
-rw-r--r-- | source/features/quick-repo-deletion.tsx | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/source/features/quick-repo-deletion.tsx b/source/features/quick-repo-deletion.tsx index f0acc819..e9871943 100644 --- a/source/features/quick-repo-deletion.tsx +++ b/source/features/quick-repo-deletion.tsx @@ -36,19 +36,14 @@ function handleToggle(event: delegate.Event<Event, HTMLDetailsElement>): void { setTimeout(start, 1, event.delegateTarget); } -async function buttonTimeout(buttonContainer: HTMLDetailsElement): Promise<boolean> { - // Watch for cancellations - const abortController = new AbortController(); - buttonContainer.addEventListener('toggle', () => { - abortController.abort(); - }, {once: true}); - - void api.expectTokenScope('delete_repo').catch((error: Error) => { +async function verifyScopesWhileWaiting(abortController: AbortController): Promise<void> { + try { + await api.expectTokenScope('delete_repo'); + } catch (error: unknown) { abortController.abort(); - buttonContainer.open = false; addNotice([ 'Could not delete the repository. ', - parseBackticks(error.message), + parseBackticks((error as Error).message), ], { type: 'error', action: ( @@ -57,7 +52,18 @@ async function buttonTimeout(buttonContainer: HTMLDetailsElement): Promise<boole </a> ), }); - }); + } +} + +async function buttonTimeout(buttonContainer: HTMLDetailsElement): Promise<boolean> { + // Sync AbortController and DOM state + const abortController = new AbortController(); + buttonContainer.addEventListener('toggle', abortController.abort, {once: true}); + abortController.signal.addEventListener('abort', () => { + buttonContainer.open = false; + }, {once: true}); + + void verifyScopesWhileWaiting(abortController); let secondsLeft = 5; const button = select('.btn', buttonContainer)!; @@ -87,9 +93,9 @@ async function start(buttonContainer: HTMLDetailsElement): Promise<void> { method: 'DELETE', json: false, }); - const restoreURL = pageDetect.isOrganizationRepo() ? - `/organizations/${owner}/settings/deleted_repositories` : - '/settings/deleted_repositories'; + const restoreURL = pageDetect.isOrganizationRepo() + ? `/organizations/${owner}/settings/deleted_repositories` + : '/settings/deleted_repositories'; const otherForksURL = `/${owner}?tab=repositories&type=fork`; addNotice( <span>Repository {nameWithOwner} deleted. You might be able to <a href={restoreURL}>restore it</a> or see <a href={otherForksURL}>your other forks.</a></span>, @@ -116,10 +122,10 @@ async function start(buttonContainer: HTMLDetailsElement): Promise<void> { async function init(): Promise<void | false> { if ( // Only if the user can delete the repository - !await elementReady('nav [data-content="Settings"]') || + !await elementReady('nav [data-content="Settings"]') // Only if the repository hasn't been starred - looseParseInt(select('.starring-container .social-count')!) > 0 + || looseParseInt(select('.starring-container .social-count')!) > 0 ) { return false; } |