aboutsummaryrefslogtreecommitdiff
path: root/src/content/reducers/setting.ts
blob: 9ca1380c867d3983aeec205f8ca308b941742b78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as actions from '../actions';
import * as keyUtils from '../../shared/utils/keys';
import * as operations from '../../shared/operations';
import { Search, Properties, DefaultSetting } from '../../shared/Settings';

export interface State {
  keymaps: { key: keyUtils.Key[], op: operations.Operation }[];
  search: Search;
  properties: Properties;
}

// defaultState does not refer due to the state is load from
// background on load.
const defaultState: State = {
  keymaps: [],
  search: DefaultSetting.search,
  properties: DefaultSetting.properties,
};

export default function reducer(
  state: State = defaultState,
  action: actions.SettingAction,
): State {
  switch (action.type) {
  case actions.SETTING_SET:
    return {
      keymaps: Object.entries(action.settings.keymaps).map((entry) => {
        return {
          key: keyUtils.fromMapKeys(entry[0]),
          op: entry[1],
        };
      }),
      properties: action.settings.properties,
      search: action.settings.search,
    };
  default:
    return state;
  }
}