33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import React , { useContext } from 'react' ;
6+ import React , { useContext , useState } from 'react' ;
77import { COPILOT_LOGINS } from '../../src/common/copilot' ;
88import { gitHubLabelColor } from '../../src/common/utils' ;
99import { IMilestone , IProjectItem , reviewerId } from '../../src/github/interface' ;
@@ -28,6 +28,8 @@ export default function Sidebar({ reviewers, labels, hasWritePermission, isIssue
2828 pr,
2929 } = useContext ( PullRequestContext ) ;
3030
31+ const [ assigningCopilot , setAssigningCopilot ] = useState ( false ) ;
32+
3133 const shouldShowCopilotButton = canAssignCopilot && assignees . every ( assignee => ! COPILOT_LOGINS . includes ( assignee . login ) ) ;
3234
3335 const updateProjects = async ( ) => {
@@ -84,9 +86,15 @@ export default function Sidebar({ reviewers, labels, hasWritePermission, isIssue
8486 id = "assign-copilot-btn"
8587 className = "icon-button"
8688 title = "Assign to Copilot"
89+ disabled = { assigningCopilot }
8790 onClick = { async ( ) => {
88- const newAssignees = await addAssigneeCopilot ( ) ;
89- updatePR ( { assignees : newAssignees . assignees , events : newAssignees . events } ) ;
91+ setAssigningCopilot ( true ) ;
92+ try {
93+ const newAssignees = await addAssigneeCopilot ( ) ;
94+ updatePR ( { assignees : newAssignees . assignees , events : newAssignees . events } ) ;
95+ } finally {
96+ setAssigningCopilot ( false ) ;
97+ }
9098 } } >
9199 { copilotIcon }
92100 </ button >
0 commit comments