1
1
import type { TaskView , TaskStepView } from '../resources/tasks' ;
2
- import { ExhaustiveSwitchCheck } from './types' ;
2
+ import { type DeepMutable , ExhaustiveSwitchCheck } from './types' ;
3
3
4
4
export type ReducerEvent = TaskView | null ;
5
5
@@ -8,8 +8,8 @@ export type BrowserState = Readonly<{
8
8
sessionId : string ;
9
9
10
10
liveUrl : string | null ;
11
-
12
11
steps : ReadonlyArray < TaskStepView > ;
12
+ doneOutput : string | null ;
13
13
} > | null ;
14
14
15
15
type BrowserAction = {
@@ -24,22 +24,25 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
24
24
25
25
if ( state == null ) {
26
26
const liveUrl = action . status . sessionLiveUrl ?? null ;
27
+ const doneOutput = action . status . doneOutput ?? null ;
27
28
28
29
const state : BrowserState = {
29
30
taskId : action . status . id ,
30
31
sessionId : action . status . sessionId ,
31
32
liveUrl : liveUrl ,
32
33
steps : action . status . steps ,
34
+ doneOutput : doneOutput ,
33
35
} ;
34
36
35
37
return [ state , action . status ] ;
36
38
}
37
39
38
40
// UPDATE
39
41
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 ;
42
44
45
+ const steps : TaskStepView [ ] = [ ...state . steps ] ;
43
46
if ( action . status . steps != null ) {
44
47
const newSteps = action . status . steps . slice ( state . steps . length ) ;
45
48
@@ -48,15 +51,25 @@ export function reducer(state: BrowserState, action: BrowserAction): [BrowserSta
48
51
}
49
52
}
50
53
51
- const newState : BrowserState = { ...state , liveUrl, steps } ;
54
+ const newState : DeepMutable < BrowserState > = {
55
+ ...state ,
56
+ liveUrl,
57
+ steps,
58
+ doneOutput,
59
+ } ;
52
60
53
61
// CHANGES
54
62
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
+ ) {
56
68
const update : ReducerEvent = {
57
69
...action . status ,
58
- steps : steps ,
59
- sessionLiveUrl : liveUrl ,
70
+ steps : newState . steps ,
71
+ sessionLiveUrl : newState . liveUrl ,
72
+ doneOutput : newState . doneOutput ,
60
73
} ;
61
74
62
75
return [ newState , update ] ;
0 commit comments