-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhotKeysSlice.ts
More file actions
60 lines (55 loc) · 1.64 KB
/
hotKeysSlice.ts
File metadata and controls
60 lines (55 loc) · 1.64 KB
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
import { createSlice } from "@reduxjs/toolkit"
import { type JSONObject } from "@common/src/json-utils"
import { VALKEY } from "@common/src/constants.ts"
import * as R from "ramda"
import type { RootState } from "@/store.ts"
export const selectHotKeys = (id: string) => (state: RootState) =>
R.path([VALKEY.HOTKEYS.name, id, "hotKeys"], state)
interface HotKeysState {
[connectionId: string]: {
hotKeys: [string, number][]
checkAt: string|null,
monitorRunning: boolean,
nodeId: string|null,
error?: JSONObject | null,
}
}
const initialHotKeysState: HotKeysState = {}
const hotKeysSlice = createSlice({
name: "hotKeys",
initialState: initialHotKeysState,
reducers: {
hotKeysRequested: (state, action) => {
const connectionId = action.payload.connectionId
if (!state[connectionId]) {
state[connectionId] = {
hotKeys: [],
checkAt: null,
monitorRunning: false,
nodeId: null,
}
}
},
hotKeysFulfilled: (state, action) => {
const { hotKeys, monitorRunning, checkAt, nodeId } = action.payload.parsedResponse
console.log("Parsed response in the frontend is: ", action.payload.parsedResponse)
const connectionId = action.payload.connectionId
state[connectionId] = {
hotKeys,
checkAt,
monitorRunning,
nodeId,
}
},
hotKeysError: (state, action) => {
const { connectionId, error } = action.payload
state[connectionId].error = error
},
},
})
export default hotKeysSlice.reducer
export const {
hotKeysRequested,
hotKeysFulfilled,
hotKeysError,
} = hotKeysSlice.actions