summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readme.md1
-rw-r--r--source/features/delete-review-comments-faster.tsx51
-rw-r--r--source/features/edit-comments-faster.tsx2
-rw-r--r--source/github-helpers/load-details-menu.ts12
-rw-r--r--source/refined-github.ts1
5 files changed, 66 insertions, 1 deletions
diff --git a/readme.md b/readme.md
index c0aaf3ad..cf3d97fc 100644
--- a/readme.md
+++ b/readme.md
@@ -176,6 +176,7 @@ Thanks for contributing! 🦋🙌
- [](# "table-input") [Adds a button in the text editor to quickly insert a simplified HTML table.](https://user-images.githubusercontent.com/46634000/94559114-09892c00-0261-11eb-8fb0-c5a85ea76b6f.gif)
- [](# "unfinished-comments") [Notifies the user of unfinished comments in hidden tabs.](https://user-images.githubusercontent.com/1402241/97792086-423d5d80-1b9f-11eb-9a3a-daf716d10b0e.gif)
- [](# "wait-for-attachments") [Wait for the attachments to finish uploading before allowing to post a comment.](https://user-images.githubusercontent.com/46634000/104294547-9b8b0c80-54bf-11eb-93e5-65ae158353b3.gif)
+- [](# "delete-review-comments-faster") [Adds a button to delete review comments in one click when editing them.](https://user-images.githubusercontent.com/46634000/115445792-9fdd6900-a216-11eb-9ba3-6dab4d2f9d32.png)
- [](# "avoid-accidental-submissions") [Disables the <kbd>enter</kbd>-to-submit shortcut in some commit/PR/issue title fields to avoid accidental submissions. Use <kbd>ctrl</kbd><kbd>enter</kbd> instead.](https://user-images.githubusercontent.com/723651/115148453-5818df00-a068-11eb-92d4-51ac6e937b8b.gif)
<!-- Refer to style guide above. Keep this message between sections. -->
diff --git a/source/features/delete-review-comments-faster.tsx b/source/features/delete-review-comments-faster.tsx
new file mode 100644
index 00000000..e4fca356
--- /dev/null
+++ b/source/features/delete-review-comments-faster.tsx
@@ -0,0 +1,51 @@
+import React from 'dom-chef';
+import select from 'select-dom';
+import delegate from 'delegate-it';
+import {observe} from 'selector-observer';
+import {TrashIcon} from '@primer/octicons-react';
+import * as pageDetect from 'github-url-detection';
+
+import features from '.';
+import loadDetailsMenu from '../github-helpers/load-details-menu';
+
+const deinit: VoidFunction[] = [];
+
+async function onButtonClick({delegateTarget: button}: delegate.Event): Promise<void> {
+ button
+ .closest('.js-comment')!
+ .querySelector('.show-more-popover .js-comment-delete > button')!
+ .click();
+}
+
+async function onEditButtonClick({delegateTarget: button}: delegate.Event): Promise<void> {
+ const comment = button.closest('.js-comment')!;
+ await loadDetailsMenu(select('details-menu.show-more-popover', comment)!);
+}
+
+function addDeleteButton(cancelButton: Element): void {
+ cancelButton.classList.add('rgh-delete-button-added');
+ cancelButton.after(
+ <button className="btn btn-danger float-left rgh-review-comment-delete-button" type="button">
+ <TrashIcon/>
+ </button>
+ );
+}
+
+function init(): void {
+ const listener = delegate(document, '.rgh-review-comment-delete-button', 'click', onButtonClick);
+ const editButtonListener = delegate(document, '.rgh-edit-comments-faster-button', 'click', onEditButtonClick);
+ const observer = observe('.review-comment > .unminimized-comment form:not(.js-single-suggested-change-form) .js-comment-cancel-button:not(.rgh-delete-button-added)', {
+ add: addDeleteButton
+ });
+ deinit.push(listener.destroy, editButtonListener.destroy, observer.abort);
+}
+
+void features.add(__filebasename, {
+ include: [
+ pageDetect.isPRConversation,
+ pageDetect.isPRFiles
+ ],
+ awaitDomReady: false,
+ init,
+ deinit
+});
diff --git a/source/features/edit-comments-faster.tsx b/source/features/edit-comments-faster.tsx
index 635f0130..86d4bfe5 100644
--- a/source/features/edit-comments-faster.tsx
+++ b/source/features/edit-comments-faster.tsx
@@ -19,7 +19,7 @@ function init(): void {
<button
type="button"
role="menuitem"
- className="timeline-comment-action btn-link js-comment-edit-button"
+ className="timeline-comment-action btn-link js-comment-edit-button rgh-edit-comments-faster-button"
aria-label="Edit comment"
>
<PencilIcon/>
diff --git a/source/github-helpers/load-details-menu.ts b/source/github-helpers/load-details-menu.ts
new file mode 100644
index 00000000..94e3dd90
--- /dev/null
+++ b/source/github-helpers/load-details-menu.ts
@@ -0,0 +1,12 @@
+import select from 'select-dom';
+import oneEvent from 'one-event';
+
+export default async function loadDetailsMenu(detailsMenu: HTMLElement): Promise<void> {
+ const fragment = select('include-fragment.SelectMenu-loading', detailsMenu);
+ if (!fragment) {
+ return;
+ }
+
+ detailsMenu.parentElement!.dispatchEvent(new Event('mouseover'));
+ await oneEvent(fragment, 'load');
+}
diff --git a/source/refined-github.ts b/source/refined-github.ts
index c4985774..a0ffd127 100644
--- a/source/refined-github.ts
+++ b/source/refined-github.ts
@@ -219,6 +219,7 @@ import './features/view-last-pr-deployment';
import './features/global-search-filters';
import './features/clean-header-search-field';
import './features/avoid-accidental-submissions';
+import './features/delete-review-comments-faster';
// Add global for easier debugging
(window as any).select = select;