Skip to content

Commit

Permalink
feat(new chat): add new chat button :)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh committed Mar 13, 2024
1 parent 2402504 commit 8e11c7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/features/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const Chat: React.FC<{ style?: React.CSSProperties }> = (props) => {
removePreviewFileByName,
retryQuestion,
maybeRequestCaps,
startNewChat,
} = useEventBusForChat();

const maybeSendToSideBar =
Expand Down Expand Up @@ -80,14 +81,17 @@ export const Chat: React.FC<{ style?: React.CSSProperties }> = (props) => {
}}
>
{host === "vscode" && !tabbed && (
<Flex gap="2" pb="3">
<Button variant="surface" onClick={backFromChat}>
<Flex gap="2" pb="3" wrap="wrap">
<Button size="1" variant="surface" onClick={backFromChat}>
<ArrowLeftIcon width="16" height="16" />
Back
</Button>
<Button variant="surface" onClick={openChatInNewTab}>
<Button size="1" variant="surface" onClick={openChatInNewTab}>
Open In Tab
</Button>
<Button size="1" variant="surface" onClick={startNewChat}>
New Chat
</Button>
</Flex>
)}
<ChatContent
Expand Down
19 changes: 18 additions & 1 deletion src/hooks/useEventBusForChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import {
isReceiveTokenCount,
FileInfo,
type ChatSetSelectedSnippet,
CreateNewChatThread,
SaveChatFromChat,
} from "../events";
import { usePostMessage } from "./usePostMessage";
import { useDebounceCallback } from "usehooks-ts";
Expand Down Expand Up @@ -150,7 +152,7 @@ function reducer(state: ChatState, action: ActionToChat): ChatState {
};
}

if (isCreateNewChat(action)) {
if (isThisChat && isCreateNewChat(action)) {
const nextState = createInitialState();

return {
Expand Down Expand Up @@ -682,6 +684,20 @@ export const useEventBusForChat = () => {
[sendMessages, state.chat.id],
);

const startNewChat = useCallback(() => {
const saveMessage: SaveChatFromChat = {
type: EVENT_NAMES_FROM_CHAT.SAVE_CHAT,
payload: state.chat,
};
postMessage(saveMessage);

const message: CreateNewChatThread = {
type: EVENT_NAMES_TO_CHAT.NEW_CHAT,
payload: { id: state.chat.id },
};
dispatch(message);
}, [postMessage, state.chat]);

return {
state,
askQuestion,
Expand All @@ -701,5 +717,6 @@ export const useEventBusForChat = () => {
removePreviewFileByName,
retryQuestion,
maybeRequestCaps,
startNewChat,
};
};

0 comments on commit 8e11c7b

Please sign in to comment.