-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplify settings reducer * Simplify settings action creators
- Loading branch information
Showing
3 changed files
with
68 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,52 @@ | ||
import { combineReducers } from 'redux'; | ||
import { clamp } from 'lodash'; | ||
|
||
const sortType = (state = 'modificationDate', action) => { | ||
if ('setSortType' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.sortType; | ||
}; | ||
|
||
const sortReversed = (state = false, action) => { | ||
if ('setSortReversed' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.sortReversed; | ||
}; | ||
|
||
const sortTagsAlpha = (state = false, action) => { | ||
if ('setSortTagsAlpha' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.sortTagsAlpha || false; | ||
}; | ||
|
||
const theme = (state = 'light', action) => { | ||
if ('setTheme' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.theme; | ||
}; | ||
|
||
const focusModeEnabled = (state = false, action) => { | ||
if ('setFocusMode' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.focusModeEnabled; | ||
}; | ||
|
||
const fontSize = (state = 16, { type, fontSize: size = 16 }) => { | ||
if ('setFontSize' !== type) { | ||
return state; | ||
} | ||
|
||
return clamp(size, 10, 30); | ||
}; | ||
|
||
const noteDisplay = (state = 'comfy', action) => { | ||
if ('setNoteDisplay' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.noteDisplay; | ||
}; | ||
|
||
const lineLength = (state = 'narrow', action) => { | ||
if ('setLineLength' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.lineLength; | ||
}; | ||
|
||
const accountName = (state = null, action) => { | ||
if ('setAccountName' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.accountName; | ||
}; | ||
|
||
const markdownEnabled = (state = false, action) => { | ||
if ('setMarkdownEnabled' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.markdownEnabled; | ||
}; | ||
|
||
const wpToken = (state = false, action) => { | ||
if ('setWPToken' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.token; | ||
}; | ||
|
||
const spellCheckEnabled = (state = true, action) => { | ||
if ('setSpellCheck' !== action.type) { | ||
return state; | ||
} | ||
|
||
return action.spellCheckEnabled; | ||
}; | ||
|
||
export default combineReducers({ | ||
accountName, | ||
focusModeEnabled, | ||
fontSize, | ||
lineLength, | ||
markdownEnabled, | ||
noteDisplay, | ||
sortType, | ||
sortReversed, | ||
sortTagsAlpha, | ||
spellCheckEnabled, | ||
theme, | ||
wpToken, | ||
}); | ||
export const initialState = { | ||
accountName: null, | ||
focusModeEnabled: false, | ||
fontSize: 16, | ||
lineLength: 'narrow', | ||
markdownEnabled: false, | ||
noteDisplay: 'comfy', | ||
sortReversed: false, | ||
sortTagsAlpha: false, | ||
sortType: 'modificationDate', | ||
spellCheckEnabled: true, | ||
theme: 'light', | ||
wpToken: false, | ||
}; | ||
|
||
function reducer(state = initialState, action) { | ||
switch (action.type) { | ||
case 'setAccountName': | ||
return { ...state, accountName: action.accountName }; | ||
case 'setFocusMode': | ||
return { ...state, focusModeEnabled: action.focusModeEnabled }; | ||
case 'setFontSize': | ||
return { | ||
...state, | ||
fontSize: clamp(action.fontSize || initialState.fontSize, 10, 30), | ||
}; | ||
case 'setLineLength': | ||
return { ...state, lineLength: action.lineLength }; | ||
case 'setMarkdownEnabled': | ||
return { ...state, markdownEnabled: action.markdownEnabled }; | ||
case 'setNoteDisplay': | ||
return { ...state, noteDisplay: action.noteDisplay }; | ||
case 'setSortReversed': | ||
return { ...state, sortReversed: action.sortReversed }; | ||
case 'setSortTagsAlpha': | ||
return { ...state, sortTagsAlpha: action.sortTagsAlpha }; | ||
case 'setSortType': | ||
return { ...state, sortType: action.sortType }; | ||
case 'setSpellCheck': | ||
return { ...state, spellCheckEnabled: action.spellCheckEnabled }; | ||
case 'setTheme': | ||
return { ...state, theme: action.theme }; | ||
case 'setWPToken': | ||
return { ...state, wpToken: action.token }; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default reducer; |