import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import elementReady from 'element-ready'; import * as pageDetect from 'github-url-detection'; import features from '.'; import onReplacedElement from '../helpers/on-replaced-element'; async function addSidebarReviewButton(): Promise { const reviewFormUrl = new URL(location.href); reviewFormUrl.pathname += '/files'; reviewFormUrl.hash = 'submit-review'; const sidebarReviewsSection = await elementReady('[aria-label="Select reviewers"] .discussion-sidebar-heading'); if (select.exists('[data-hotkey="v"]', sidebarReviewsSection)) { return false; } sidebarReviewsSection!.append( review now ); } function focusReviewTextarea({delegateTarget}: delegate.Event): void { if (delegateTarget.open) { select('textarea', delegateTarget)!.focus(); } } async function initReviewButtonEnhancements(): Promise { delegate(document, '.js-reviews-container > details', 'toggle', focusReviewTextarea, true); const reviewDropdownButton = await elementReady('.js-reviews-toggle'); if (reviewDropdownButton) { reviewDropdownButton.dataset.hotkey = 'v'; // This feature should be native but isn't currently working #3681 if (location.hash === '#submit-review') { reviewDropdownButton.click(); } } } void features.add(__filebasename, { include: [ pageDetect.isPRConversation ], additionalListeners: [ () => void onReplacedElement('#partial-discussion-sidebar', addSidebarReviewButton) ], awaitDomReady: false, init: addSidebarReviewButton }, { shortcuts: { v: 'Open PR review popup' }, include: [ pageDetect.isPRFiles ], awaitDomReady: false, init: initReviewButtonEnhancements });