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 {ICodeReq} from '../../models/code'; 18 19interface IState { 20 isRunLoading: boolean 21 isCompileLoading: boolean 22 code: string 23 compileRes: ICodeReq | null 24 runRes: ICodeReq | null 25} 26 27const initialState: IState = { 28 isRunLoading: false, 29 isCompileLoading: false, 30 code: '', 31 compileRes: null, 32 runRes: null 33}; 34 35const codeSlice = createSlice({ 36 name: 'codeState', 37 initialState, 38 reducers: { 39 setRunLoading(state, action: PayloadAction<boolean>) { 40 state.isRunLoading = action.payload; 41 }, 42 setCompileLoading(state, action: PayloadAction<boolean>) { 43 state.isCompileLoading = action.payload; 44 }, 45 setCode(state, action: PayloadAction<string>) { 46 state.code = action.payload; 47 }, 48 setCompileRes(state, action: PayloadAction<ICodeReq | null>) { 49 state.compileRes = action.payload; 50 }, 51 setRunRes(state, action: PayloadAction<ICodeReq | null>) { 52 state.runRes = action.payload; 53 }, 54 } 55}); 56 57export const { 58 setRunLoading, 59 setCompileLoading, 60 setCode, 61 setCompileRes, 62 setRunRes 63} = codeSlice.actions; 64 65export default codeSlice.reducer; 66