@@ -325,7 +325,7 @@ export const workspaceMachine = createMachine(
325
325
} ,
326
326
} ,
327
327
requestingStart : {
328
- entry : "clearBuildError" ,
328
+ entry : [ "clearBuildError" , "updateStatusToPending" ] ,
329
329
invoke : {
330
330
src : "startWorkspace" ,
331
331
id : "startWorkspace" ,
@@ -344,7 +344,7 @@ export const workspaceMachine = createMachine(
344
344
} ,
345
345
} ,
346
346
requestingStop : {
347
- entry : "clearBuildError" ,
347
+ entry : [ "clearBuildError" , "updateStatusToPending" ] ,
348
348
invoke : {
349
349
src : "stopWorkspace" ,
350
350
id : "stopWorkspace" ,
@@ -363,7 +363,7 @@ export const workspaceMachine = createMachine(
363
363
} ,
364
364
} ,
365
365
requestingDelete : {
366
- entry : "clearBuildError" ,
366
+ entry : [ "clearBuildError" , "updateStatusToPending" ] ,
367
367
invoke : {
368
368
src : "deleteWorkspace" ,
369
369
id : "deleteWorkspace" ,
@@ -382,7 +382,11 @@ export const workspaceMachine = createMachine(
382
382
} ,
383
383
} ,
384
384
requestingCancel : {
385
- entry : [ "clearCancellationMessage" , "clearCancellationError" ] ,
385
+ entry : [
386
+ "clearCancellationMessage" ,
387
+ "clearCancellationError" ,
388
+ "updateStatusToPending" ,
389
+ ] ,
386
390
invoke : {
387
391
src : "cancelWorkspace" ,
388
392
id : "cancelWorkspace" ,
@@ -430,9 +434,7 @@ export const workspaceMachine = createMachine(
430
434
on : {
431
435
REFRESH_TIMELINE : {
432
436
target : "#workspaceState.ready.timeline.gettingBuilds" ,
433
- cond : {
434
- type : "moreBuildsAvailable" ,
435
- } ,
437
+ cond : "moreBuildsAvailable" ,
436
438
} ,
437
439
} ,
438
440
} ,
@@ -599,6 +601,24 @@ export const workspaceMachine = createMachine(
599
601
} ) ,
600
602
{ to : "scheduleBannerMachine" } ,
601
603
) ,
604
+ // Optimistically update. So when the user clicks on stop, we can show
605
+ // the "pending" state right away without having to wait 0.5s ~ 2s to
606
+ // display the visual feedback to the user.
607
+ updateStatusToPending : assign ( {
608
+ workspace : ( { workspace } ) => {
609
+ if ( ! workspace ) {
610
+ throw new Error ( "Workspace not defined" )
611
+ }
612
+
613
+ return {
614
+ ...workspace ,
615
+ latest_build : {
616
+ ...workspace . latest_build ,
617
+ status : "pending" as TypesGen . WorkspaceStatus ,
618
+ } ,
619
+ }
620
+ } ,
621
+ } ) ,
602
622
} ,
603
623
guards : {
604
624
moreBuildsAvailable,
0 commit comments