command-slice.ts 725 B

12345678910111213141516171819202122232425262728293031
  1. import { createSlice } from "@reduxjs/toolkit";
  2. export type Command = {
  3. content: string;
  4. type: "input" | "output";
  5. };
  6. const initialCommands: Command[] = [];
  7. export const commandSlice = createSlice({
  8. name: "command",
  9. initialState: {
  10. commands: initialCommands,
  11. },
  12. reducers: {
  13. appendInput: (state, action) => {
  14. state.commands.push({ content: action.payload, type: "input" });
  15. },
  16. appendOutput: (state, action) => {
  17. state.commands.push({ content: action.payload, type: "output" });
  18. },
  19. clearTerminal: (state) => {
  20. state.commands = [];
  21. },
  22. },
  23. });
  24. export const { appendInput, appendOutput, clearTerminal } =
  25. commandSlice.actions;
  26. export default commandSlice.reducer;