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, UiStateMode } from '../actions/Action';
18
19export type ContextState = {
20  uiEnable: boolean,
21  uiStateMode: UiStateMode,
22  deviceHeight: number,
23  footBarWidth: number,
24  footBarHeight: number,
25  isThirdPartyCall: boolean,
26  thirdCallAction: string,
27  isFaCall: boolean,
28  permissionFlag: boolean,
29  action: string,
30  isKeepScreenOn: boolean,
31  initShowFlag: boolean
32}
33
34const initState: ContextState = {
35  uiEnable: true,
36  uiStateMode: UiStateMode.NONE,
37  deviceHeight: 0,
38  footBarWidth: 0,
39  footBarHeight: 0,
40  isThirdPartyCall: false,
41  thirdCallAction: '',
42  isFaCall: false,
43  permissionFlag: false,
44  action: '',
45  isKeepScreenOn: false,
46  initShowFlag: false
47}
48
49export function contextReducer(state = initState, action: ActionData): ContextState {
50  switch (action.type) {
51    case Action.ACTION_UI_STATE:
52      return {
53        ...state, uiEnable: action.data.enable, uiStateMode: action.data.uiStateMode
54      };
55    case Action.ACTION_INIT_FOOT_BAR_WIDTH:
56      return {
57        ...state, footBarWidth: action.data.footBarWidth
58      };
59    case Action.ACTION_INIT_FOOT_BAR_HEIGHT:
60      return {
61        ...state, footBarHeight: action.data.footBarHeight
62      };
63    case Action.ACTION_THIRD_PARTY_CALL:
64      return {
65        ...state, isThirdPartyCall: action.data.isThirdPartyCall, thirdCallAction: action.data.thirdCallAction
66      };
67    case Action.ACTION_FA_CALL:
68      return {
69        ...state, isFaCall: action.data.isFaCall
70      };
71    case Action.ACTION_SET_PERMISSION_FLAG:
72      return {
73        ...state, permissionFlag: action.data.permissionFlag
74      };
75    case Action.ACTION_INIT_ACTION:
76      return {
77        ...state, action: action.data.action
78      };
79    case Action.ACTION_KEEP_SCREEN_ON:
80      return {
81        ...state, isKeepScreenOn: action.data.isKeepScreenOn
82      };
83    case Action.ACTION_UPDATE_INIT_SHOW_FLAG:
84      return {
85        ...state, initShowFlag: action.data.initShowFlag
86      };
87    default:
88      return state;
89  }
90}