-
Notifications
You must be signed in to change notification settings - Fork 10
/
reducer.ts
87 lines (81 loc) · 2.42 KB
/
reducer.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { createSlice } from "@reduxjs/toolkit";
import { AppState } from "../typings/types";
import { v4 as uuid_v4 } from "uuid";
const initialNotebookId = uuid_v4()
const initialCellId1 = uuid_v4()
const initialCellId2 = uuid_v4()
const initialState: AppState = {
interpreterMode: "node",
activeNotebookName: "note1.dnb",
notebooks: {
"note1.dnb": {
notebookId: initialNotebookId,
name: "note1.dnb",
cellIds: [initialCellId1],
cells: {
[initialCellId1]: {
id: initialCellId1,
content: "",
mode: "javascript",
output: ""
},
},
},
"note2.dnb": {
notebookId: uuid_v4(),
name: "note2.dnb",
cellIds: [initialCellId2],
cells: {
[initialCellId2]: {
id: initialCellId2,
content: "",
mode: "markdown",
output: ""
},
},
},
},
config: {
cellTheme: "monokai",
cellFontSize: 14,
cellEnableBasicAutocompletion: true,
cellEnableLiveAutocompletion: true,
cellEnableSnippets: true,
cellShowLineNumbers: false,
cellTabSize: 2,
width: "100%",
notebookThemeMode: "light",
autosaveNotebook: true,
}
}
const appReducer = createSlice({
name: "app",
initialState: { ...initialState },
reducers: {
setInterpreterMode: (state, action) => {
state.interpreterMode = action.payload;
},
updateCellIds: (state, action) => {
const { newCellIds, activeNotebookName } = action.payload;
state.notebooks[activeNotebookName].cellIds = newCellIds;
},
updateCells: (state, action) => {
const { newCells, activeNotebookName } = action.payload;
state.notebooks[activeNotebookName].cells = newCells;
},
updateConfig: (state, action) => {
state.config = action.payload;
},
updateActiveNotebookName: (state, action) => {
state.activeNotebookName = action.payload;
},
}
});
export const {
setInterpreterMode,
updateCellIds,
updateCells,
updateConfig,
updateActiveNotebookName,
} = appReducer.actions;
export default appReducer.reducer;