@@ -3,55 +3,67 @@ import { createSelector, createSlice } from '@reduxjs/toolkit';
3
3
import type { PersistConfig , RootState } from 'app/store/store' ;
4
4
import { canvasReset } from 'features/controlLayers/store/actions' ;
5
5
import { canvasSessionReset , generateSessionReset } from 'features/controlLayers/store/canvasStagingAreaSlice' ;
6
- import type { Dimensions } from 'features/controlLayers/store/types' ;
7
6
import { workflowLoaded } from 'features/nodes/store/nodesSlice' ;
8
7
import { atom } from 'nanostores' ;
9
8
10
- import type { CanvasRightPanelTabName , TabName , UIState } from './uiTypes' ;
11
-
12
- const initialUIState : UIState = {
13
- _version : 3 ,
14
- activeTab : 'canvas' ,
15
- activeTabCanvasRightPanel : 'gallery' ,
16
- shouldShowImageDetails : false ,
17
- shouldShowProgressInViewer : true ,
18
- accordions : { } ,
19
- expanders : { } ,
20
- textAreaSizes : { } ,
21
- shouldShowNotificationV2 : true ,
22
- } ;
9
+ import type { TabName , UIState } from './uiTypes' ;
10
+ import { getInitialUIState } from './uiTypes' ;
23
11
24
12
export const uiSlice = createSlice ( {
25
13
name : 'ui' ,
26
- initialState : initialUIState ,
14
+ initialState : getInitialUIState ( ) ,
27
15
reducers : {
28
- setActiveTab : ( state , action : PayloadAction < TabName > ) => {
16
+ setActiveTab : ( state , action : PayloadAction < UIState [ 'activeTab' ] > ) => {
29
17
state . activeTab = action . payload ;
30
18
} ,
31
- activeTabCanvasRightPanelChanged : ( state , action : PayloadAction < CanvasRightPanelTabName > ) => {
19
+ activeTabCanvasRightPanelChanged : ( state , action : PayloadAction < UIState [ 'activeTabCanvasRightPanel' ] > ) => {
32
20
state . activeTabCanvasRightPanel = action . payload ;
33
21
} ,
34
- setShouldShowImageDetails : ( state , action : PayloadAction < boolean > ) => {
22
+ setShouldShowImageDetails : ( state , action : PayloadAction < UIState [ 'shouldShowImageDetails' ] > ) => {
35
23
state . shouldShowImageDetails = action . payload ;
36
24
} ,
37
- setShouldShowProgressInViewer : ( state , action : PayloadAction < boolean > ) => {
25
+ setShouldShowProgressInViewer : ( state , action : PayloadAction < UIState [ 'shouldShowProgressInViewer' ] > ) => {
38
26
state . shouldShowProgressInViewer = action . payload ;
39
27
} ,
40
- accordionStateChanged : ( state , action : PayloadAction < { id : string ; isOpen : boolean } > ) => {
28
+ accordionStateChanged : (
29
+ state ,
30
+ action : PayloadAction < {
31
+ id : keyof UIState [ 'accordions' ] ;
32
+ isOpen : UIState [ 'accordions' ] [ keyof UIState [ 'accordions' ] ] ;
33
+ } >
34
+ ) => {
41
35
const { id, isOpen } = action . payload ;
42
36
state . accordions [ id ] = isOpen ;
43
37
} ,
44
- expanderStateChanged : ( state , action : PayloadAction < { id : string ; isOpen : boolean } > ) => {
38
+ expanderStateChanged : (
39
+ state ,
40
+ action : PayloadAction < {
41
+ id : keyof UIState [ 'expanders' ] ;
42
+ isOpen : UIState [ 'expanders' ] [ keyof UIState [ 'expanders' ] ] ;
43
+ } >
44
+ ) => {
45
45
const { id, isOpen } = action . payload ;
46
46
state . expanders [ id ] = isOpen ;
47
47
} ,
48
- textAreaSizesStateChanged : ( state , action : PayloadAction < { id : string ; size : Partial < Dimensions > } > ) => {
48
+ textAreaSizesStateChanged : (
49
+ state ,
50
+ action : PayloadAction < {
51
+ id : keyof UIState [ 'textAreaSizes' ] ;
52
+ size : UIState [ 'textAreaSizes' ] [ keyof UIState [ 'textAreaSizes' ] ] ;
53
+ } >
54
+ ) => {
49
55
const { id, size } = action . payload ;
50
56
state . textAreaSizes [ id ] = size ;
51
57
} ,
52
- shouldShowNotificationChanged : ( state , action : PayloadAction < boolean > ) => {
58
+ shouldShowNotificationChanged : ( state , action : PayloadAction < UIState [ 'shouldShowNotificationV2' ] > ) => {
53
59
state . shouldShowNotificationV2 = action . payload ;
54
60
} ,
61
+ showGenerateTabSplashScreenChanged : ( state , action : PayloadAction < UIState [ 'showGenerateTabSplashScreen' ] > ) => {
62
+ state . showGenerateTabSplashScreen = action . payload ;
63
+ } ,
64
+ showCanvasTabSplashScreenChanged : ( state , action : PayloadAction < UIState [ 'showCanvasTabSplashScreen' ] > ) => {
65
+ state . showCanvasTabSplashScreen = action . payload ;
66
+ } ,
55
67
} ,
56
68
extraReducers ( builder ) {
57
69
builder . addCase ( workflowLoaded , ( state ) => {
@@ -81,6 +93,8 @@ export const {
81
93
expanderStateChanged,
82
94
shouldShowNotificationChanged,
83
95
textAreaSizesStateChanged,
96
+ showGenerateTabSplashScreenChanged,
97
+ showCanvasTabSplashScreenChanged,
84
98
} = uiSlice . actions ;
85
99
86
100
export const selectUiSlice = ( state : RootState ) => state . ui ;
@@ -103,7 +117,7 @@ const migrateUIState = (state: any): any => {
103
117
104
118
export const uiPersistConfig : PersistConfig < UIState > = {
105
119
name : uiSlice . name ,
106
- initialState : initialUIState ,
120
+ initialState : getInitialUIState ( ) ,
107
121
migrate : migrateUIState ,
108
122
persistDenylist : [ 'shouldShowImageDetails' ] ,
109
123
} ;
0 commit comments