1/* 2 * Copyright (c) 2024-2025 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 isShareLoading: boolean 23 code: string 24 compileRes: ICodeReq | null 25 runRes: ICodeReq | null 26 verifierRes: ICodeReq | null 27} 28 29const initialState: IState = { 30 isRunLoading: false, 31 isCompileLoading: false, 32 isShareLoading: false, 33 code: 'console.log("Hello, ArkTS!");', 34 compileRes: null, 35 runRes: null, 36 verifierRes: null 37}; 38 39const codeSlice = createSlice({ 40 name: 'codeState', 41 initialState, 42 reducers: { 43 setRunLoading(state, action: PayloadAction<boolean>) { 44 state.isRunLoading = action.payload; 45 }, 46 setCompileLoading(state, action: PayloadAction<boolean>) { 47 state.isCompileLoading = action.payload; 48 }, 49 setShareLoading(state, action: PayloadAction<boolean>) { 50 state.isShareLoading = action.payload; 51 }, 52 setCode(state, action: PayloadAction<string>) { 53 state.code = action.payload; 54 }, 55 setCompileRes(state, action: PayloadAction<ICodeReq | null>) { 56 state.compileRes = action.payload; 57 }, 58 setRunRes(state, action: PayloadAction<ICodeReq | null>) { 59 state.runRes = action.payload; 60 }, 61 } 62}); 63 64export const { 65 setRunLoading, 66 setCompileLoading, 67 setShareLoading, 68 setCode, 69 setCompileRes, 70 setRunRes 71} = codeSlice.actions; 72 73export default codeSlice.reducer; 74