1/* 2 * Copyright (c) 2024 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 { createSlice, PayloadAction } from '@reduxjs/toolkit'; 17import { IOption } from '../../models/options'; 18 19export interface IObj { 20 [key: string]: boolean | number | string; 21} 22 23interface IState { 24 isLoading: boolean 25 options: IOption[] | null 26 pickedOptions: IObj | null 27} 28 29const initialState: IState = { 30 isLoading: false, 31 options: null, 32 pickedOptions: {}, 33}; 34 35const optionsSlice = createSlice({ 36 name: 'optionsState', 37 initialState, 38 reducers: { 39 setOptionsLoading(state, action: PayloadAction<boolean>) { 40 state.isLoading = action.payload; 41 }, 42 setOptionsResponse(state, action: PayloadAction<IOption[]>) { 43 state.options = action.payload; 44 }, 45 setOptionsPicked(state, action: PayloadAction<IObj>) { 46 state.pickedOptions = action.payload; 47 } 48 } 49}); 50 51export const { 52 setOptionsLoading, 53 setOptionsResponse, 54 setOptionsPicked, 55} = optionsSlice.actions; 56 57export default optionsSlice.reducer; 58