@@ -4,6 +4,28 @@ import {
44 createReducer ,
55 Reducer
66} from "hard-reducer"
7+ import v8n from "v8n"
8+
9+ v8n . extend ( {
10+ acceptableTheme ( ) {
11+ return ( value : string ) => [ "dark" , "default" ] . includes ( value )
12+ }
13+ } )
14+
15+ export const rules = {
16+ committerName : v8n ( ) . string ( ) ,
17+ committerEmail : v8n ( ) . string ( ) ,
18+ githubApiToken : v8n ( ) . string ( ) ,
19+ editorFontScale : v8n ( ) . number ( ) ,
20+ editorFontFamily : v8n ( ) . string ( ) ,
21+ editorSpellCheck : v8n ( ) . boolean ( ) ,
22+ githubProxy : v8n ( ) . string ( ) ,
23+ theme : v8n ( )
24+ . string ( )
25+ . acceptableTheme ( ) ,
26+ isFirstVisit : v8n ( ) . boolean ( ) ,
27+ doneTutorial : v8n ( ) . boolean ( )
28+ }
729
830const { createAction } = buildActionCreator ( {
931 prefix : "config/"
@@ -14,6 +36,9 @@ export type ConfigState = {
1436 committerEmail : string
1537 githubApiToken : string
1638 githubProxy : string
39+ editorSpellCheck : boolean
40+ editorFontFamily : string
41+ editorFontScale : number
1742 isFirstVisit : boolean
1843 doneTutorial : boolean
1944 theme : string
@@ -22,12 +47,22 @@ export type ConfigState = {
2247export const setConfigValue : ActionCreator < {
2348 key : string
2449 value : string | boolean
25- } > = createAction ( "set-config-value" )
50+ valid : boolean
51+ } > = createAction ( "set-config-value" , input => {
52+ const rule = ( rules as any ) [ input . key ]
53+ return {
54+ ...input ,
55+ valid : rule . test ( input . value )
56+ }
57+ } )
2658
2759const initalState : ConfigState = {
2860 committerName : "" ,
2961 committerEmail : "" ,
3062 githubApiToken : "" ,
63+ editorFontScale : 1.0 ,
64+ editorFontFamily : "Inconsolata, monospace" ,
65+ editorSpellCheck : false ,
3166 githubProxy : "https://cors-buster-zashozaqfk.now.sh/github.com/" ,
3267 theme : "dark" ,
3368 isFirstVisit : true ,
@@ -36,10 +71,15 @@ const initalState: ConfigState = {
3671
3772export const reducer : Reducer < ConfigState > = createReducer ( initalState ) . case (
3873 setConfigValue ,
39- ( state , { key, value } ) => {
40- return {
41- ...state ,
42- [ key ] : value
43- } as any
74+ ( state , { key, value, valid } ) => {
75+ if ( valid ) {
76+ return {
77+ ...state ,
78+ [ key ] : value
79+ } as any
80+ } else {
81+ console . warn ( `You can not set ${ key } : ${ value } ` )
82+ return state
83+ }
4484 }
4585)
0 commit comments