@@ -49,6 +49,7 @@ export const CreateClone = observer((props: Props) => {
4949 const timer = useTimer ( )
5050 const [ branchesList , setBranchesList ] = useState < string [ ] > ( [ ] )
5151 const [ snapshots , setSnapshots ] = useState ( [ ] as Snapshot [ ] )
52+ const [ isLoadingSnapshots , setIsLoadingSnapshots ] = useState ( false )
5253
5354 // Form.
5455 const onSubmit = async ( values : FormValues ) => {
@@ -94,6 +95,7 @@ export const CreateClone = observer((props: Props) => {
9495
9596 const fetchData = async ( ) => {
9697 try {
98+ setIsLoadingSnapshots ( true )
9799 await stores . main . load ( props . instanceId )
98100
99101 const branches = ( await stores . main . getBranches ( ) ) ?? [ ]
@@ -105,12 +107,15 @@ export const CreateClone = observer((props: Props) => {
105107 await fetchBranchSnapshotsData ( initiallySelectedBranch )
106108 } else {
107109 const allSnapshots = stores . main ?. snapshots ?. data ?? [ ]
108- setSnapshots ( allSnapshots )
110+ const sortedSnapshots = allSnapshots . slice ( ) . sort ( compareSnapshotsDesc )
111+ setSnapshots ( sortedSnapshots )
109112 const [ firstSnapshot ] = allSnapshots ?? [ ]
110113 formik . setFieldValue ( 'snapshotId' , firstSnapshot ?. id )
111114 }
112115 } catch ( error ) {
113116 console . error ( 'Error fetching data:' , error )
117+ } finally {
118+ setIsLoadingSnapshots ( false )
114119 }
115120 }
116121
@@ -136,7 +141,7 @@ export const CreateClone = observer((props: Props) => {
136141 )
137142
138143 // Initial loading spinner.
139- if ( ! stores . main . instance )
144+ if ( ! stores . main . instance || isLoadingSnapshots )
140145 return (
141146 < >
142147 { headRendered }
@@ -217,23 +222,20 @@ export const CreateClone = observer((props: Props) => {
217222 }
218223 error = { Boolean ( formik . errors . snapshotId ) }
219224 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+ } ) ?? [ ]
237239 }
238240 />
239241
0 commit comments