11import i18next from 'i18next' ;
2+ import {
3+ UserPreferences as Preferences ,
4+ AppThemeOptions ,
5+ UpdatePreferencesRequestBody
6+ } from '../../../../common/types' ;
27import { apiClient } from '../../../utils/apiClient' ;
38import * as ActionTypes from '../../../constants' ;
9+ import { PreferencesState } from '../reducers/preferences' ;
10+ import { RootState } from '../../../reducers' ;
411
5- function updatePreferences ( formParams , dispatch ) {
12+ export type UpdatePreferencesDispatch = ( action : unknown ) => void ;
13+ export type GetRootState = ( ) => RootState ;
14+
15+ function updatePreferences (
16+ formParams : UpdatePreferencesRequestBody ,
17+ dispatch : UpdatePreferencesDispatch
18+ ) {
619 apiClient
720 . put ( '/preferences' , formParams )
821 . then ( ( ) => { } )
@@ -14,15 +27,15 @@ function updatePreferences(formParams, dispatch) {
1427 } ) ;
1528}
1629
17- export function setPreferencesTab ( value ) {
30+ export function setPreferencesTab ( value : PreferencesState [ 'tabIndex' ] ) {
1831 return {
1932 type : ActionTypes . SET_PREFERENCES_TAB ,
2033 value
2134 } ;
2235}
2336
24- export function setFontSize ( value ) {
25- return ( dispatch , getState ) => {
37+ export function setFontSize ( value : PreferencesState [ 'fontSize' ] ) {
38+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
2639 // eslint-disable-line
2740 dispatch ( {
2841 type : ActionTypes . SET_FONT_SIZE ,
@@ -41,7 +54,7 @@ export function setFontSize(value) {
4154}
4255
4356export function setLineNumbers ( value ) {
44- return ( dispatch , getState ) => {
57+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
4558 dispatch ( {
4659 type : ActionTypes . SET_LINE_NUMBERS ,
4760 value
@@ -59,7 +72,7 @@ export function setLineNumbers(value) {
5972}
6073
6174export function setAutocloseBracketsQuotes ( value ) {
62- return ( dispatch , getState ) => {
75+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
6376 dispatch ( {
6477 type : ActionTypes . SET_AUTOCLOSE_BRACKETS_QUOTES ,
6578 value
@@ -77,7 +90,7 @@ export function setAutocloseBracketsQuotes(value) {
7790}
7891
7992export function setAutocompleteHinter ( value ) {
80- return ( dispatch , getState ) => {
93+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
8194 dispatch ( {
8295 type : ActionTypes . SET_AUTOCOMPLETE_HINTER ,
8396 value
@@ -95,7 +108,7 @@ export function setAutocompleteHinter(value) {
95108}
96109
97110export function setAutosave ( value ) {
98- return ( dispatch , getState ) => {
111+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
99112 dispatch ( {
100113 type : ActionTypes . SET_AUTOSAVE ,
101114 value
@@ -113,7 +126,7 @@ export function setAutosave(value) {
113126}
114127
115128export function setLinewrap ( value ) {
116- return ( dispatch , getState ) => {
129+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
117130 dispatch ( {
118131 type : ActionTypes . SET_LINEWRAP ,
119132 value
@@ -131,7 +144,7 @@ export function setLinewrap(value) {
131144}
132145
133146export function setLintWarning ( value ) {
134- return ( dispatch , getState ) => {
147+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
135148 dispatch ( {
136149 type : ActionTypes . SET_LINT_WARNING ,
137150 value
@@ -149,7 +162,7 @@ export function setLintWarning(value) {
149162}
150163
151164export function setTextOutput ( value ) {
152- return ( dispatch , getState ) => {
165+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
153166 dispatch ( {
154167 type : ActionTypes . SET_TEXT_OUTPUT ,
155168 value
@@ -167,7 +180,7 @@ export function setTextOutput(value) {
167180}
168181
169182export function setGridOutput ( value ) {
170- return ( dispatch , getState ) => {
183+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
171184 dispatch ( {
172185 type : ActionTypes . SET_GRID_OUTPUT ,
173186 value
@@ -185,11 +198,7 @@ export function setGridOutput(value) {
185198}
186199
187200export function setTheme ( value ) {
188- // return {
189- // type: ActionTypes.SET_THEME,
190- // value
191- // };
192- return ( dispatch , getState ) => {
201+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
193202 dispatch ( {
194203 type : ActionTypes . SET_THEME ,
195204 value
@@ -207,11 +216,7 @@ export function setTheme(value) {
207216}
208217
209218export function setAutorefresh ( value ) {
210- // return {
211- // type: ActionTypes.SET_AUTOREFRESH,
212- // value
213- // };
214- return ( dispatch , getState ) => {
219+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
215220 dispatch ( {
216221 type : ActionTypes . SET_AUTOREFRESH ,
217222 value
@@ -229,14 +234,14 @@ export function setAutorefresh(value) {
229234}
230235
231236export function setAllAccessibleOutput ( value ) {
232- return ( dispatch ) => {
237+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
233238 dispatch ( setTextOutput ( value ) ) ;
234239 dispatch ( setGridOutput ( value ) ) ;
235240 } ;
236241}
237242
238243export function setLanguage ( value , { persistPreference = true } = { } ) {
239- return ( dispatch , getState ) => {
244+ return ( dispatch : UpdatePreferencesDispatch , getState : GetRootState ) => {
240245 i18next . changeLanguage ( value ) ;
241246 dispatch ( {
242247 type : ActionTypes . SET_LANGUAGE ,
0 commit comments