@@ -49,6 +49,7 @@ export const CreateClone = observer((props: Props) => {
49
49
const timer = useTimer ( )
50
50
const [ branchesList , setBranchesList ] = useState < string [ ] > ( [ ] )
51
51
const [ snapshots , setSnapshots ] = useState ( [ ] as Snapshot [ ] )
52
+ const [ isLoadingSnapshots , setIsLoadingSnapshots ] = useState ( false )
52
53
53
54
// Form.
54
55
const onSubmit = async ( values : FormValues ) => {
@@ -94,6 +95,7 @@ export const CreateClone = observer((props: Props) => {
94
95
95
96
const fetchData = async ( ) => {
96
97
try {
98
+ setIsLoadingSnapshots ( true )
97
99
await stores . main . load ( props . instanceId )
98
100
99
101
const branches = ( await stores . main . getBranches ( ) ) ?? [ ]
@@ -105,12 +107,15 @@ export const CreateClone = observer((props: Props) => {
105
107
await fetchBranchSnapshotsData ( initiallySelectedBranch )
106
108
} else {
107
109
const allSnapshots = stores . main ?. snapshots ?. data ?? [ ]
108
- setSnapshots ( allSnapshots )
110
+ const sortedSnapshots = allSnapshots . slice ( ) . sort ( compareSnapshotsDesc )
111
+ setSnapshots ( sortedSnapshots )
109
112
const [ firstSnapshot ] = allSnapshots ?? [ ]
110
113
formik . setFieldValue ( 'snapshotId' , firstSnapshot ?. id )
111
114
}
112
115
} catch ( error ) {
113
116
console . error ( 'Error fetching data:' , error )
117
+ } finally {
118
+ setIsLoadingSnapshots ( false )
114
119
}
115
120
}
116
121
@@ -136,7 +141,7 @@ export const CreateClone = observer((props: Props) => {
136
141
)
137
142
138
143
// Initial loading spinner.
139
- if ( ! stores . main . instance )
144
+ if ( ! stores . main . instance || isLoadingSnapshots )
140
145
return (
141
146
< >
142
147
{ headRendered }
@@ -217,23 +222,20 @@ export const CreateClone = observer((props: Props) => {
217
222
}
218
223
error = { Boolean ( formik . errors . snapshotId ) }
219
224
items = {
220
- snapshots
221
- . slice ( )
222
- . sort ( compareSnapshotsDesc )
223
- . map ( ( snapshot , i ) => {
224
- const isLatest = i === 0
225
- return {
226
- value : snapshot . id ,
227
- children : (
228
- < >
229
- { snapshot . dataStateAt }
230
- { isLatest && (
231
- < span className = { styles . snapshotTag } > Latest</ span >
232
- ) }
233
- </ >
234
- ) ,
235
- }
236
- } ) ?? [ ]
225
+ snapshots . map ( ( snapshot , i ) => {
226
+ const isLatest = i === 0
227
+ return {
228
+ value : snapshot . id ,
229
+ children : (
230
+ < >
231
+ { snapshot . dataStateAt }
232
+ { isLatest && (
233
+ < span className = { styles . snapshotTag } > Latest</ span >
234
+ ) }
235
+ </ >
236
+ ) ,
237
+ }
238
+ } ) ?? [ ]
237
239
}
238
240
/>
239
241
0 commit comments