Skip to content

Commit

Permalink
Add history state to ConsoleState and implement addToHistory action i…
Browse files Browse the repository at this point in the history
…n console slice
  • Loading branch information
walidkayhan committed Jan 20, 2025
1 parent 295aa32 commit 4df4292
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/app/src/store/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,6 @@ export interface SerialPortOptions {
}

export interface ConsoleState {
history: string[];
inputHistory: string[];
}
10 changes: 8 additions & 2 deletions src/app/src/store/redux/slices/console.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const MAX_HISTORY_SIZE = 1000;

const initialState: ConsoleState = {
inputHistory: [],
history: [],
};

const consoleSlice = createSlice({
Expand All @@ -16,14 +17,19 @@ const consoleSlice = createSlice({
state.inputHistory = action.payload.slice(-MAX_HISTORY_SIZE);
},
addToInputHistory(state, action: PayloadAction<string>) {
// Add new entry and remove oldest if exceeding limit
state.inputHistory = [...state.inputHistory, action.payload].slice(
-MAX_HISTORY_SIZE,
);
},
addToHistory(state, action: PayloadAction<string>) {
state.history = [...state.history, action.payload].slice(
-MAX_HISTORY_SIZE,
);
},
},
});

export const { setInputHistory, addToInputHistory } = consoleSlice.actions;
export const { setInputHistory, addToInputHistory, addToHistory } =
consoleSlice.actions;

export default consoleSlice.reducer;

0 comments on commit 4df4292

Please sign in to comment.