@@ -32,7 +32,7 @@ export const NewProjectRepoSelection: FC<Props> = ({ selectedProviderHost, onPro
32
32
const createProject = useCreateProject ( ) ;
33
33
34
34
// Component state managed by this component
35
- const [ selectedAccount , _setSelectedAccount ] = useState < string > ( ) ;
35
+ const [ selectedAccount , setSelectedAccount ] = useState < string > ( ) ;
36
36
const [ repoSearchFilter , setRepoSearchFilter ] = useState ( "" ) ;
37
37
const [ installationId , setInstallationId ] = useState < string > ( ) ;
38
38
@@ -43,8 +43,8 @@ export const NewProjectRepoSelection: FC<Props> = ({ selectedProviderHost, onPro
43
43
} ) ;
44
44
45
45
// Wrap setting selected account so we can clear the repo search filter at the same time
46
- const updateSelectedAccount = useCallback ( ( account ?: string ) => {
47
- _setSelectedAccount ( account ) ;
46
+ const setSelectedAccountAndClearSearch = useCallback ( ( account ?: string ) => {
47
+ setSelectedAccount ( account ) ;
48
48
setRepoSearchFilter ( "" ) ;
49
49
} , [ ] ) ;
50
50
@@ -117,22 +117,22 @@ export const NewProjectRepoSelection: FC<Props> = ({ selectedProviderHost, onPro
117
117
[ onCreateProject ] ,
118
118
) ;
119
119
120
- // Adjusts selectedAccount when repos change
120
+ // Adjusts selectedAccount when repos change if we don't have a selected account
121
121
useEffect ( ( ) => {
122
122
if ( reposInAccounts ?. length === 0 ) {
123
- updateSelectedAccount ( undefined ) ;
124
- } else {
123
+ setSelectedAccountAndClearSearch ( undefined ) ;
124
+ } else if ( ! selectedAccount ) {
125
125
const first = reposInAccounts ?. [ 0 ] ;
126
126
if ( ! ! first ?. installationUpdatedAt ) {
127
127
const mostRecent = reposInAccounts ?. reduce ( ( prev , current ) =>
128
128
( prev . installationUpdatedAt || 0 ) > ( current . installationUpdatedAt || 0 ) ? prev : current ,
129
129
) ;
130
- updateSelectedAccount ( mostRecent ?. account ) ;
130
+ setSelectedAccountAndClearSearch ( mostRecent ?. account ) ;
131
131
} else {
132
- updateSelectedAccount ( first ?. account ) ;
132
+ setSelectedAccountAndClearSearch ( first ?. account ) ;
133
133
}
134
134
}
135
- } , [ reposInAccounts , updateSelectedAccount ] ) ;
135
+ } , [ reposInAccounts , selectedAccount , setSelectedAccountAndClearSearch ] ) ;
136
136
137
137
if ( isLoading ) {
138
138
return < ReposLoading /> ;
@@ -150,7 +150,7 @@ export const NewProjectRepoSelection: FC<Props> = ({ selectedProviderHost, onPro
150
150
accounts = { accounts }
151
151
selectedAccount = { selectedAccount }
152
152
selectedProviderHost = { selectedProviderHost }
153
- onAccountSelected = { updateSelectedAccount }
153
+ onAccountSelected = { setSelectedAccountAndClearSearch }
154
154
onAddGitHubAccount = { reconfigure }
155
155
onSelectGitProvider = { onChangeGitProvider }
156
156
/>
0 commit comments