• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { Action, ActionData } from '../actions/Action'
17
18export type ModeState = {
19  isInitiated: boolean,
20  mode: string,
21  curMode: string,
22  isShowBigText: boolean,
23  modeIndex: number,
24  swipeModeIndex: number,
25  isShowMoreList: boolean,
26  modeChangeDone: boolean,
27}
28
29const initState: ModeState = {
30  isInitiated: false,
31  mode: 'PHOTO',
32  curMode: 'PHOTO',
33  isShowBigText: false,
34  modeIndex: 1,
35  swipeModeIndex: 1,
36  isShowMoreList: false,
37  modeChangeDone: false,
38}
39
40export default function ModeReducer(state = initState, action: ActionData): ModeState {
41  switch (action.type) {
42  case Action.ACTION_SWIPE_MODE_DONE:
43    return { ...state, modeChangeDone: action.data.modeChangeDone }
44  case Action.ACTION_INIT_MODE:
45    return { ...state, mode: action.data.mode, isInitiated: true }
46  case Action.ACTION_CHANGE_MODE:
47    return { ...state, mode: action.data.mode }
48  case Action.ACTION_SET_MODE:
49    return { ...state, mode: action.data.mode }
50  case Action.ACTION_UPDATE_MODE:
51    return { ...state, curMode: action.data.mode }
52  case Action.ACTION_UPDATE_MODE_INDEX:
53    return { ...state, modeIndex: action.data.modeIndex }
54  case Action.ACTION_SWIPE_MODE:
55    return {...state, swipeModeIndex: action.data.swipeModeIndex}
56  case Action.ACTION_UPDATE_SHOW_BIG_TEXT_FLAG:
57    return { ...state, isShowBigText: action.data.isShowBigText }
58  case Action.ACTION_UPDATE_SHOW_MORE_LIST:
59    return {...state, isShowMoreList: action.data.isShowMoreList}
60  default:
61    return state;
62  }
63}