@@ -17,7 +17,8 @@ import {
17
17
DROP_NOTICE ,
18
18
ADD_NOTICE ,
19
19
ROUTE_CHANGED ,
20
- INITIAL_ROUTE } from './actions'
20
+ INITIAL_ROUTE ,
21
+ } from './actions'
21
22
22
23
import { Assets , BrandingOptions , VersionProps } from '../../adminjs-options.interface'
23
24
import { PageJSON , ResourceJSON } from '../interfaces'
@@ -27,199 +28,223 @@ import { Locale } from '../../locale/config'
27
28
import { NoticeMessage } from '../hoc/with-notice'
28
29
29
30
export type DashboardInState = {
30
- component ?: string ;
31
+ component ?: string
31
32
}
32
33
33
34
export type NoticeMessageInState = NoticeMessage & {
34
- message : string ;
35
- id : string ;
36
- type : NoticeMessage [ 'type' ] ;
37
- progress : number ;
35
+ message : string
36
+ id : string
37
+ type : NoticeMessage [ 'type' ]
38
+ progress : number
38
39
}
39
40
40
41
export type Paths = {
41
- rootPath : string ;
42
- logoutPath : string ;
43
- loginPath : string ;
44
- assetsCDN ?: string ;
42
+ rootPath : string
43
+ logoutPath : string
44
+ loginPath : string
45
+ assetsCDN ?: string
45
46
}
46
47
47
48
const resourcesReducer = (
48
49
state : Array < ResourceJSON > = [ ] ,
49
50
action : {
50
- type : string ;
51
- data : Array < ResourceJSON > ;
52
- } ,
51
+ type : string
52
+ data : Array < ResourceJSON >
53
+ }
53
54
) => {
54
55
switch ( action . type ) {
55
- case RESOURCES_INITIALIZE :
56
- return action . data
57
- default : return state
56
+ case RESOURCES_INITIALIZE :
57
+ return action . data
58
+ default :
59
+ return state
58
60
}
59
61
}
60
62
61
63
const pagesReducer = (
62
64
state : Array < PageJSON > = [ ] ,
63
65
action : {
64
- type : string ;
65
- data : Array < PageJSON > ;
66
- } ,
66
+ type : string
67
+ data : Array < PageJSON >
68
+ }
67
69
) => {
68
70
switch ( action . type ) {
69
- case PAGES_INITIALIZE :
70
- return action . data
71
- default : return state
71
+ case PAGES_INITIALIZE :
72
+ return action . data
73
+ default :
74
+ return state
72
75
}
73
76
}
74
77
75
78
const localesReducer = (
76
79
state : Locale = { language : 'en' , translations : { } } as Locale ,
77
80
action : {
78
- type : string ;
79
- data : Locale ;
80
- } ,
81
+ type : string
82
+ data : Locale
83
+ }
81
84
) => {
82
85
switch ( action . type ) {
83
- case LOCALE_INITIALIZE :
84
- return action . data
85
- default : return state
86
+ case LOCALE_INITIALIZE :
87
+ return action . data
88
+ default :
89
+ return state
86
90
}
87
91
}
88
92
89
- const brandingReducer = ( state = { } , action : {
90
- type : string ;
91
- data : BrandingOptions ;
92
- } ) => {
93
+ const brandingReducer = (
94
+ state = { } ,
95
+ action : {
96
+ type : string
97
+ data : BrandingOptions
98
+ }
99
+ ) => {
93
100
switch ( action . type ) {
94
- case BRANDING_INITIALIZE :
95
- return action . data
96
- default : return state
101
+ case BRANDING_INITIALIZE :
102
+ return action . data
103
+ default :
104
+ return state
97
105
}
98
106
}
99
107
100
- const assetsReducer = ( state = { } , action : {
101
- type : string ;
102
- data : Assets ;
103
- } ) => {
108
+ const assetsReducer = (
109
+ state = { } ,
110
+ action : {
111
+ type : string
112
+ data : Assets
113
+ }
114
+ ) => {
104
115
switch ( action . type ) {
105
- case ASSETS_INITIALIZE :
106
- return action . data
107
- default : return state
116
+ case ASSETS_INITIALIZE :
117
+ return action . data
118
+ default :
119
+ return state
108
120
}
109
121
}
110
122
111
- const pathsReducer = (
112
- state : Paths = DEFAULT_PATHS ,
113
- action : { type : string ; data : Paths } ,
114
- ) : Paths => {
123
+ const pathsReducer = ( state : Paths = DEFAULT_PATHS , action : { type : string ; data : Paths } ) : Paths => {
115
124
switch ( action . type ) {
116
- case PATHS_INITIALIZE :
117
- return action . data
118
- default : return state
125
+ case PATHS_INITIALIZE :
126
+ return action . data
127
+ default :
128
+ return state
119
129
}
120
130
}
121
131
122
- const dashboardReducer = ( state = { } , action : {
123
- type : string ;
124
- data : DashboardInState ;
125
- } ) : DashboardInState => {
132
+ const dashboardReducer = (
133
+ state = { } ,
134
+ action : {
135
+ type : string
136
+ data : DashboardInState
137
+ }
138
+ ) : DashboardInState => {
126
139
switch ( action . type ) {
127
- case DASHBOARD_INITIALIZE :
128
- return action . data
129
- default : return state
140
+ case DASHBOARD_INITIALIZE :
141
+ return action . data
142
+ default :
143
+ return state
130
144
}
131
145
}
132
146
133
147
const sessionReducer = (
134
148
state : CurrentAdmin | null = null ,
135
149
action : {
136
- type : string ;
137
- data : CurrentAdmin | null ;
138
- } ,
150
+ type : string
151
+ data : CurrentAdmin | null
152
+ }
139
153
) => {
140
154
switch ( action . type ) {
141
- case SESSION_INITIALIZE :
142
- return action . data
143
- default : return state
155
+ case SESSION_INITIALIZE :
156
+ return action . data
157
+ default :
158
+ return state
144
159
}
145
160
}
146
161
147
- const versionsReducer = ( state = { } , action : {
148
- type : string ;
149
- data : VersionProps ;
150
- } ) => {
162
+ const versionsReducer = (
163
+ state = { } ,
164
+ action : {
165
+ type : string
166
+ data : VersionProps
167
+ }
168
+ ) => {
151
169
switch ( action . type ) {
152
- case VERSIONS_INITIALIZE :
153
- return {
154
- admin : action . data . admin ,
155
- app : action . data . app ,
156
- }
157
- default : return state
170
+ case VERSIONS_INITIALIZE :
171
+ return {
172
+ admin : action . data . admin ,
173
+ app : action . data . app ,
174
+ }
175
+ default :
176
+ return state
158
177
}
159
178
}
160
179
161
180
export type RouterProps = {
162
- from : Partial < ReturnType < typeof useLocation > > ;
163
- to : Partial < ReturnType < typeof useLocation > > ;
181
+ from : Partial < ReturnType < typeof useLocation > >
182
+ to : Partial < ReturnType < typeof useLocation > >
164
183
}
165
184
166
- const routerReducer = ( state : RouterProps = { from : { } , to : { } } , action : {
167
- type : string ;
168
- data : any ;
169
- } ) => {
185
+ const routerReducer = (
186
+ state : RouterProps = { from : { } , to : { } } ,
187
+ action : {
188
+ type : string
189
+ data : any
190
+ }
191
+ ) => {
170
192
switch ( action . type ) {
171
- case INITIAL_ROUTE :
172
- return {
173
- ...state ,
174
- from : { ...action . data } ,
175
- }
176
- case ROUTE_CHANGED :
177
- return {
178
- from : { ...state . to } ,
179
- to : { ...action . data } ,
180
- }
181
- default : return state
193
+ case INITIAL_ROUTE :
194
+ return {
195
+ ...state ,
196
+ from : { ...action . data } ,
197
+ }
198
+ case ROUTE_CHANGED :
199
+ return {
200
+ from : { ...state . to } ,
201
+ to : { ...action . data } ,
202
+ }
203
+ default :
204
+ return state
182
205
}
183
206
}
184
207
185
208
type NoticeArgs = { noticeId : string ; progress : number }
186
209
187
- const noticesReducer = ( state : Array < NoticeMessageInState > = [ ] , action : {
188
- type : string ;
189
- data : NoticeMessageInState | NoticeArgs ;
190
- } ) : Array < NoticeMessageInState > => {
191
- switch ( action . type ) {
192
- case ADD_NOTICE : {
193
- const notices = [ action . data as NoticeMessageInState ]
194
- return notices
195
- }
196
- case DROP_NOTICE : {
197
- return state . filter ( ( notice ) => notice . id !== ( action . data as NoticeArgs ) . noticeId )
198
- }
199
- case SET_NOTICE_PROGRESS : {
200
- return state . map ( ( notice ) => ( {
201
- ...notice ,
202
- progress : notice . id === ( action . data as NoticeArgs ) . noticeId
203
- ? action . data . progress
204
- : notice . progress ,
205
- } ) )
210
+ const noticesReducer = (
211
+ state : Array < NoticeMessageInState > = [ ] ,
212
+ action : {
213
+ type : string
214
+ data : NoticeMessageInState | NoticeArgs
206
215
}
207
- default : return state
216
+ ) : Array < NoticeMessageInState > => {
217
+ switch ( action . type ) {
218
+ case ADD_NOTICE : {
219
+ const notices = [ action . data as NoticeMessageInState ]
220
+ return notices
221
+ }
222
+ case DROP_NOTICE : {
223
+ return state . filter ( ( notice ) => notice . id !== ( action . data as NoticeArgs ) . noticeId )
224
+ }
225
+ case SET_NOTICE_PROGRESS : {
226
+ return state . map ( ( notice ) => ( {
227
+ ...notice ,
228
+ progress : notice . id === ( action . data as NoticeArgs ) . noticeId ? action . data . progress : notice . progress ,
229
+ } ) )
230
+ }
231
+ default :
232
+ return state
208
233
}
209
234
}
210
235
211
236
export type ReduxState = {
212
- resources : Array < ResourceJSON > ;
213
- branding : BrandingOptions ;
214
- assets : Assets ;
215
- paths : Paths ;
216
- session : CurrentAdmin | null ;
217
- dashboard : DashboardInState ;
218
- notices : Array < NoticeMessageInState > ;
219
- versions : VersionProps ;
220
- pages : Array < PageJSON > ;
221
- locale : Locale ;
222
- router : RouterProps ;
237
+ resources : Array < ResourceJSON >
238
+ branding : BrandingOptions
239
+ assets : Assets
240
+ paths : Paths
241
+ session : CurrentAdmin | null
242
+ dashboard : DashboardInState
243
+ notices : Array < NoticeMessageInState >
244
+ versions : VersionProps
245
+ pages : Array < PageJSON >
246
+ locale : Locale
247
+ router : RouterProps
223
248
}
224
249
225
250
const reducer = combineReducers < ReduxState > ( {
0 commit comments