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 type { ActionData } from '../actions/Action';
17import { Action } from '../actions/Action';
18
19export type ModeState = {
20  isInitiated: boolean,
21  mode: string,
22  curMode: string,
23  isShowBigText: boolean,
24  modeIndex: number,
25  swipeModeIndex: number,
26  isShowMoreList: boolean,
27  modeChangeDone: boolean,
28}
29
30const initState: ModeState = {
31  isInitiated: false,
32  mode: 'PHOTO',
33  curMode: 'PHOTO',
34  isShowBigText: false,
35  modeIndex: 0,
36  swipeModeIndex: 0,
37  isShowMoreList: false,
38  modeChangeDone: false,
39}
40
41export function modeReducer(state = initState, action: ActionData): ModeState {
42  switch (action.type) {
43    case Action.ACTION_SWIPE_MODE_DONE:
44      return { ...state, modeChangeDone: action.data.modeChangeDone };
45    case Action.ACTION_INIT_MODE:
46      return { ...state, mode: action.data.mode, isInitiated: true };
47    case Action.ACTION_CHANGE_MODE:
48      return { ...state, mode: action.data.mode };
49    case Action.ACTION_SET_MODE:
50      return { ...state, mode: action.data.mode };
51    case Action.ACTION_UPDATE_MODE:
52      return { ...state, curMode: action.data.mode };
53    case Action.ACTION_UPDATE_MODE_INDEX:
54      return { ...state, modeIndex: action.data.modeIndex };
55    case Action.ACTION_SWIPE_MODE:
56      return { ...state, swipeModeIndex: action.data.swipeModeIndex };
57    case Action.ACTION_UPDATE_SHOW_BIG_TEXT_FLAG:
58      return { ...state, isShowBigText: action.data.isShowBigText };
59    case Action.ACTION_UPDATE_SHOW_MORE_LIST:
60      return { ...state, isShowMoreList: action.data.isShowMoreList };
61    default:
62      return state;
63  }
64}