@@ -16,6 +16,7 @@ export default function BranchListComponent({ repoId, currentBranch }) {
16
16
const [ errorBranch , setErrorBranch ] = useState ( "" ) ;
17
17
const [ deleteSuccess , setDeleteSuccess ] = useState ( false ) ;
18
18
const [ deleteError , setDeleteError ] = useState ( false ) ;
19
+ const [ loading , setLoading ] = useState ( false ) ;
19
20
20
21
function resetStates ( ) {
21
22
setListError ( false ) ;
@@ -31,6 +32,7 @@ export default function BranchListComponent({ repoId, currentBranch }) {
31
32
const token = axios . CancelToken ;
32
33
const source = token . source ( ) ;
33
34
35
+ setLoading ( true ) ;
34
36
setBranchList ( [ ] ) ;
35
37
36
38
axios ( {
@@ -50,6 +52,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
50
52
} ,
51
53
} )
52
54
. then ( ( res ) => {
55
+ setLoading ( false ) ;
56
+
53
57
if ( res . data . data && ! res . data . error ) {
54
58
let {
55
59
gitAllBranchList,
@@ -75,6 +79,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
75
79
}
76
80
} )
77
81
. catch ( ( err ) => {
82
+ setLoading ( false ) ;
83
+
78
84
if ( err ) {
79
85
console . log ( "API error occurred : " + err ) ;
80
86
setListError ( true ) ;
@@ -86,6 +92,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
86
92
87
93
function switchBranchHandler ( branchName ) {
88
94
resetStates ( ) ;
95
+ setLoading ( true ) ;
96
+ setBranchList ( [ ] ) ;
89
97
axios ( {
90
98
url : globalAPIEndpoint ,
91
99
method : "POST" ,
@@ -98,6 +106,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
98
106
} ,
99
107
} )
100
108
. then ( ( res ) => {
109
+ setLoading ( false ) ;
110
+
101
111
if ( res . data . data && ! res . data . error ) {
102
112
const checkoutStatus = res . data . data . checkoutBranch ;
103
113
if ( checkoutStatus === "CHECKOUT_FAILED" ) {
@@ -115,6 +125,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
115
125
}
116
126
} )
117
127
. catch ( ( err ) => {
128
+ setLoading ( false ) ;
129
+
118
130
if ( err ) {
119
131
setSwitchError ( true ) ;
120
132
setErrorBranch ( branchName ) ;
@@ -124,6 +136,7 @@ export default function BranchListComponent({ repoId, currentBranch }) {
124
136
125
137
function deleteBranchHandler ( branchName , forceFlag ) {
126
138
resetStates ( ) ;
139
+ setLoading ( true ) ;
127
140
128
141
axios ( {
129
142
url : globalAPIEndpoint ,
@@ -139,6 +152,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
139
152
} ,
140
153
} )
141
154
. then ( ( res ) => {
155
+ setLoading ( false ) ;
156
+
142
157
if ( res . data . data && ! res . data . error ) {
143
158
if ( res . data . data . deleteBranch . status === "BRANCH_DELETE_SUCCESS" ) {
144
159
setDeleteSuccess ( true ) ;
@@ -150,6 +165,8 @@ export default function BranchListComponent({ repoId, currentBranch }) {
150
165
}
151
166
} )
152
167
. catch ( ( err ) => {
168
+ setLoading ( false ) ;
169
+
153
170
if ( err ) {
154
171
setDeleteError ( true ) ;
155
172
setErrorBranch ( branchName ) ;
@@ -199,7 +216,7 @@ export default function BranchListComponent({ repoId, currentBranch }) {
199
216
Click on a branch to checkout to that branch
200
217
</ div >
201
218
< div className = "branchlist--list-area" style = { { height : "400px" } } >
202
- { branchList . length === 0 && ! listError ? (
219
+ { loading ? (
203
220
< div className = "text-center font-sans font-light text-xl my-2 text-gray-600 border-b border-dotted" >
204
221
Collecting branch list...
205
222
</ div >
0 commit comments