summaryrefslogtreecommitdiff
path: root/blocks/eda-frontend/src/redux/simulationSlice.js
blob: 7ae6490f364ff3f20201c5b4a4808abad643cf67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { createSlice } from '@reduxjs/toolkit'

const initialState = {
  isSimulating: false,
  title: '',
  isGraph: false,
  text: [],
  errorMessage: '',
  graph: {},
  isSimRes: false,
  taskId: '',
  scriptTaskId: ''
}

const simulationSlice = createSlice({
  name: 'simulation',
  initialState,
  reducers: {
    resetResult: (state) => {
      state.isSimulating = false
      state.title = ''
      state.isGraph = false
      state.text = []
      state.errorMessage = ''
      state.graph = {}
      state.isSimRes = false
      state.taskId = ''
    },
    setSimulating: (state, action) => {
      state.isSimulating = action.payload
    },
    setResultTitle: (state, action) => {
      state.title = action.payload
    },
    setResultGraph: (state, action) => {
      state.isSimRes = true
      state.isGraph = true
      state.graph = action.payload
    },
    setResultText: (state, action) => {
      state.isSimRes = true
      state.isGraph = false
      state.text = action.payload
    },
    setErrorMessage: (state, action) => {
      state.isSimulating = false
      state.isGraph = false
      state.errorMessage = action.payload
    },
    setResultTaskId: (state, action) => {
      state.taskId = action.payload
    },
    setScriptTaskId: (state, action) => {
      state.scriptTaskId = action.payload
    }
  }
})

export const {
  resetResult,
  setSimulating,
  setResultTitle,
  setResultGraph,
  setResultText,
  setErrorMessage,
  setResultTaskId,
  setScriptTaskId
} = simulationSlice.actions

export default simulationSlice.reducer