11import type { TaskView , TaskStepView } from '../resources/tasks' ;
2- import { ExhaustiveSwitchCheck } from './types' ;
2+ import { type DeepMutable , ExhaustiveSwitchCheck } from './types' ;
33
44export type ReducerEvent = TaskView | null ;
55
@@ -8,8 +8,8 @@ export type BrowserState = Readonly<{
88 sessionId : string ;
99
1010 liveUrl : string | null ;
11-
1211 steps : ReadonlyArray < TaskStepView > ;
12+ doneOutput : string | null ;
1313} > | null ;
1414
1515type BrowserAction = {
@@ -24,22 +24,25 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
2424
2525 if ( state == null ) {
2626 const liveUrl = action . status . sessionLiveUrl ?? null ;
27+ const doneOutput = action . status . doneOutput ?? null ;
2728
2829 const state : BrowserState = {
2930 taskId : action . status . id ,
3031 sessionId : action . status . sessionId ,
3132 liveUrl : liveUrl ,
3233 steps : action . status . steps ,
34+ doneOutput : doneOutput ,
3335 } ;
3436
3537 return [ state , action . status ] ;
3638 }
3739
3840 // UPDATE
3941
40- const liveUrl = action . status . sessionLiveUrl ?? null ;
41- const steps : TaskStepView [ ] = [ ... state . steps ] ;
42+ const liveUrl = action . status . sessionLiveUrl ?? state . liveUrl ;
43+ const doneOutput = action . status . doneOutput ?? state . doneOutput ;
4244
45+ const steps : TaskStepView [ ] = [ ...state . steps ] ;
4346 if ( action . status . steps != null ) {
4447 const newSteps = action . status . steps . slice ( state . steps . length ) ;
4548
@@ -48,15 +51,25 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
4851 }
4952 }
5053
51- const newState : BrowserState = { ...state , liveUrl, steps } ;
54+ const newState : DeepMutable < BrowserState > = {
55+ ...state ,
56+ liveUrl,
57+ steps,
58+ doneOutput,
59+ } ;
5260
5361 // CHANGES
5462
55- if ( ( state . liveUrl == null && liveUrl != null ) || state . steps . length !== steps . length ) {
63+ if (
64+ ( state . liveUrl == null && liveUrl != null ) ||
65+ state . steps . length !== steps . length ||
66+ state . doneOutput != doneOutput
67+ ) {
5668 const update : ReducerEvent = {
5769 ...action . status ,
58- steps : steps ,
59- sessionLiveUrl : liveUrl ,
70+ steps : newState . steps ,
71+ sessionLiveUrl : newState . liveUrl ,
72+ doneOutput : newState . doneOutput ,
6073 } ;
6174
6275 return [ newState , update ] ;
0 commit comments