From 6d6e2fa974557fd24b2c40c850c37729c23f2df8 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Fri, 28 Feb 2025 00:04:42 -0800 Subject: [PATCH] fix annoying refactor --- .../react/src/sidebar-tsx/SidebarChat.tsx | 2 +- .../contrib/void/browser/sidebarActions.ts | 4 +-- .../contrib/void/common/chatThreadService.ts | 25 ++++++++++--------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index 09d03a16..d3c08eaf 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -979,7 +979,7 @@ export const SidebarChat = () => { const previousMessages = currentThread?.messages ?? [] const selections = currentThread.state.stagingSelections - const setSelections = (s: StagingSelectionItem[]) => { chatThreadsService.setCurrentThreadStagingSelections(s) } + const setSelections = (s: StagingSelectionItem[]) => { chatThreadsService.setCurrentThreadState({ stagingSelections: s }) } // stream state const currThreadStreamState = useChatThreadsStreamState(chatThreadsState.currentThreadId) diff --git a/src/vs/workbench/contrib/void/browser/sidebarActions.ts b/src/vs/workbench/contrib/void/browser/sidebarActions.ts index 499c9887..551a8cc8 100644 --- a/src/vs/workbench/contrib/void/browser/sidebarActions.ts +++ b/src/vs/workbench/contrib/void/browser/sidebarActions.ts @@ -141,8 +141,8 @@ registerAction2(class extends Action2 { let setSelections = (s: StagingSelectionItem[]) => { } if (focusedMessageIdx === undefined) { - selections = chatThreadService.getCurrentThreadStagingSelections() - setSelections = (s: StagingSelectionItem[]) => chatThreadService.setCurrentThreadStagingSelections(s) + selections = chatThreadService.getCurrentThreadState().stagingSelections + setSelections = (s: StagingSelectionItem[]) => chatThreadService.setCurrentThreadState({ stagingSelections: s }) } else { selections = chatThreadService.getCurrentMessageState(focusedMessageIdx).stagingSelections setSelections = (s) => chatThreadService.setCurrentMessageState(focusedMessageIdx, { stagingSelections: s }) diff --git a/src/vs/workbench/contrib/void/common/chatThreadService.ts b/src/vs/workbench/contrib/void/common/chatThreadService.ts index 57d9dfe1..2704cd58 100644 --- a/src/vs/workbench/contrib/void/common/chatThreadService.ts +++ b/src/vs/workbench/contrib/void/common/chatThreadService.ts @@ -94,13 +94,18 @@ export type ChatThreads = { state: { stagingSelections: StagingSelectionItem[]; focusedMessageIdx: number | undefined; // index of the message that is being edited (undefined if none) - isCheckedOfSelectionId: { [selectionId: string]: boolean }; + isCheckedOfSelectionId: { [selectionId: string]: boolean }; // TODO } }; } type ThreadType = ChatThreads[string] +const defaultThreadState: ThreadType['state'] = { + stagingSelections: [], + focusedMessageIdx: undefined, + isCheckedOfSelectionId: {} +} export type ThreadsState = { allThreads: ChatThreads; @@ -124,11 +129,7 @@ const newThreadObject = () => { createdAt: now, lastModified: now, messages: [], - state: { - stagingSelections: [], - focusedMessageIdx: undefined, - isCheckedOfSelectionId: {} - }, + state: defaultThreadState, } satisfies ChatThreads[string] } @@ -159,8 +160,8 @@ export interface IChatThreadService { // exposed getters/setters getCurrentMessageState: (messageIdx: number) => UserMessageState setCurrentMessageState: (messageIdx: number, newState: Partial) => void - getCurrentThreadStagingSelections: () => StagingSelectionItem[] - setCurrentThreadStagingSelections: (stagingSelections: StagingSelectionItem[]) => void + getCurrentThreadState: () => ThreadType['state'] + setCurrentThreadState: (newState: Partial) => void // call to edit a message @@ -589,13 +590,13 @@ class ChatThreadService extends Disposable implements IChatThreadService { } - getCurrentThreadStagingSelections = () => { + getCurrentThreadState = () => { const currentThread = this.getCurrentThread() - return currentThread.state.stagingSelections + return currentThread.state } - setCurrentThreadStagingSelections = (stagingSelections: StagingSelectionItem[]) => { - this._setCurrentThreadState({ stagingSelections }) + setCurrentThreadState = (newState: Partial) => { + this._setCurrentThreadState(newState) } // gets `staging` and `setStaging` of the currently focused element, given the index of the currently selected message (or undefined if no message is selected)