Skip to content

Commit b31ffcc

Browse files
committed
feat: add settings slice and types for managing application settings
1 parent a971d7d commit b31ffcc

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2+
import { SettingsState } from "./types";
3+
4+
const initialState: SettingsState = {
5+
scriptsEnabled: true,
6+
maxExecutionTime: 5000,
7+
logExecutions: true,
8+
theme: "light",
9+
autoUpdateScripts: false,
10+
};
11+
12+
const settingsSlice = createSlice({
13+
name: "settings",
14+
initialState,
15+
reducers: {
16+
updateSettings: (state, action: PayloadAction<Partial<SettingsState>>) => {
17+
Object.assign(state, action.payload);
18+
},
19+
20+
toggleScriptsEnabled: (state) => {
21+
state.scriptsEnabled = !state.scriptsEnabled;
22+
},
23+
24+
setMaxExecutionTime: (state, action: PayloadAction<number>) => {
25+
state.maxExecutionTime = Math.max(1000, Math.min(30000, action.payload));
26+
},
27+
28+
toggleLogExecutions: (state) => {
29+
state.logExecutions = !state.logExecutions;
30+
},
31+
32+
setTheme: (state, action: PayloadAction<"light" | "dark">) => {
33+
state.theme = action.payload;
34+
},
35+
36+
toggleAutoUpdateScripts: (state) => {
37+
state.autoUpdateScripts = !state.autoUpdateScripts;
38+
},
39+
40+
resetSettings: (state) => {
41+
Object.assign(state, initialState);
42+
},
43+
},
44+
});
45+
46+
export const {
47+
updateSettings,
48+
toggleScriptsEnabled,
49+
setMaxExecutionTime,
50+
toggleLogExecutions,
51+
setTheme,
52+
toggleAutoUpdateScripts,
53+
resetSettings,
54+
} = settingsSlice.actions;
55+
56+
export default settingsSlice.reducer;

src/features/settings/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface SettingsState {
2+
scriptsEnabled: boolean;
3+
maxExecutionTime: number;
4+
logExecutions: boolean;
5+
theme: "light" | "dark";
6+
autoUpdateScripts: boolean;
7+
}

0 commit comments

Comments
 (0)