@@ -17,7 +17,8 @@ import {
1717 DROP_NOTICE ,
1818 ADD_NOTICE ,
1919 ROUTE_CHANGED ,
20- INITIAL_ROUTE } from './actions'
20+ INITIAL_ROUTE ,
21+ } from './actions'
2122
2223import { Assets , BrandingOptions , VersionProps } from '../../adminjs-options.interface'
2324import { PageJSON , ResourceJSON } from '../interfaces'
@@ -27,199 +28,223 @@ import { Locale } from '../../locale/config'
2728import { NoticeMessage } from '../hoc/with-notice'
2829
2930export type DashboardInState = {
30- component ?: string ;
31+ component ?: string
3132}
3233
3334export 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
3839}
3940
4041export 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
4546}
4647
4748const resourcesReducer = (
4849 state : Array < ResourceJSON > = [ ] ,
4950 action : {
50- type : string ;
51- data : Array < ResourceJSON > ;
52- } ,
51+ type : string
52+ data : Array < ResourceJSON >
53+ }
5354) => {
5455 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
5860 }
5961}
6062
6163const pagesReducer = (
6264 state : Array < PageJSON > = [ ] ,
6365 action : {
64- type : string ;
65- data : Array < PageJSON > ;
66- } ,
66+ type : string
67+ data : Array < PageJSON >
68+ }
6769) => {
6870 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
7275 }
7376}
7477
7578const localesReducer = (
7679 state : Locale = { language : 'en' , translations : { } } as Locale ,
7780 action : {
78- type : string ;
79- data : Locale ;
80- } ,
81+ type : string
82+ data : Locale
83+ }
8184) => {
8285 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
8690 }
8791}
8892
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+ ) => {
93100 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
97105 }
98106}
99107
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+ ) => {
104115 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
108120 }
109121}
110122
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 => {
115124 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
119129 }
120130}
121131
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 => {
126139 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
130144 }
131145}
132146
133147const sessionReducer = (
134148 state : CurrentAdmin | null = null ,
135149 action : {
136- type : string ;
137- data : CurrentAdmin | null ;
138- } ,
150+ type : string
151+ data : CurrentAdmin | null
152+ }
139153) => {
140154 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
144159 }
145160}
146161
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+ ) => {
151169 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
158177 }
159178}
160179
161180export 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 > >
164183}
165184
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+ ) => {
170192 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
182205 }
183206}
184207
185208type NoticeArgs = { noticeId : string ; progress : number }
186209
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
206215 }
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
208233 }
209234}
210235
211236export 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
223248}
224249
225250const reducer = combineReducers < ReduxState > ( {
0 commit comments