Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/stores/useConsoleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { create } from 'zustand';

import { ActionTypes } from '../constants/ActionTypes';
interface State {
text: any;
text: Array<{ text: string; length: number }>;
active: boolean;
fullExpanded: boolean;
suggestions: any;
Expand All @@ -12,6 +12,8 @@ interface State {
actions: { [key: number]: (action: any) => void };
}

const CONSOLE_TEXT_LIMIT = 1_000;

const useConsoleStore = create<State>((set) => ({
text: [],
active: false,
Expand All @@ -22,7 +24,7 @@ const useConsoleStore = create<State>((set) => ({
//
actions: {
[ActionTypes.TOGGLE_CONSOLE_ACTIVE]: () => {
set((state: any) => {
set((state) => {
if (!state.active) {
return {
suggestions: [],
Expand Down Expand Up @@ -53,9 +55,9 @@ const useConsoleStore = create<State>((set) => ({
});
},
[ActionTypes.ADD_CONSOLE_TEXT]: (action: any) => {
set((state: any) => {
set((state) => {
let text = action.text.trim();
const finalStateText = [...state.text];
const finalStateText = state.text.splice(-CONSOLE_TEXT_LIMIT + 1);

if (text.startsWith('Unknown console command "')) {
let lastIndex = text.lastIndexOf('"');
Expand Down Expand Up @@ -201,7 +203,7 @@ const useConsoleStore = create<State>((set) => ({
});
},
[ActionTypes.SET_CONSOLE_SUGGESTIONS]: (action: any) => {
set((state: any) => {
set((state) => {
if (!state.active) {
return {};
}
Expand All @@ -212,7 +214,7 @@ const useConsoleStore = create<State>((set) => ({
});
},
[ActionTypes.EXECUTE_CONSOLE_COMMAND]: (action: any) => {
set((state: any) => {
set((state) => {
if (action.command.trim().length === 0) {
return {};
}
Expand Down