import { Keymap , UserConfiguration } from 'uhk-common' ; import { Actions , ActionTypes , AddKeymapSelectedAction , LoadDefaultUserConfigurationSuccessAction } from '../actions/default-user-configuration.actions' ; export interface State { loading : boolean ; userConfiguration ? : UserConfiguration ; selectedKeymapAbbreviation ? : string ; } export const initialState = { loading : false } ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case ActionTypes . AddKeymapSelected : return { ... state , selectedKeymapAbbreviation : ( action as AddKeymapSelectedAction ) . payload } ; case ActionTypes . LoadDefaultUserConfiguration : return { ... state , loading : true } ; case ActionTypes . LoadDefaultUserConfigurationSuccess : return { ... state , loading : false , userConfiguration : ( action as LoadDefaultUserConfigurationSuccessAction ) . payload } ; default : return state ; } } export const getDefaultUserConfigurationKeymaps = ( state ) : Array < Keymap > => state . userConfiguration ?. keymaps || [ ] ; export const getSelectedKeymap = ( state ) : Keymap => getDefaultUserConfigurationKeymaps ( state ) . find ( keymap => keymap . abbreviation === state . selectedKeymapAbbreviation ) || new Keymap ( ) ;