Skip to content

Commit 8b7194a

Browse files
drew-harrisskeptrunedev
authored andcommitted
fix: chat height
1 parent 8a0d992 commit 8b7194a

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

clients/search-component/src/TrieveModal/ModeSwitch.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useModalState } from "../utils/hooks/modal-context";
33
import { SparklesIcon } from "./icons";
44
import { useChatState } from "../utils/hooks/chat-context";
55
import { cn } from "../utils/styles";
6+
import { useChatHeight } from "../utils/hooks/useChatHeight";
67

78
export const ChatModeSwitch = () => {
89
const { props, mode, query, setOpen } = useModalState();
@@ -55,20 +56,26 @@ export const ModeSwitch = () => {
5556

5657
export const PopupChatCloseButton = () => {
5758
const { props, setOpen } = useModalState();
59+
const { resetHeight } = useChatHeight();
5860

5961
const { messages, isDoneReading, stopGeneratingMessage, clearConversation } =
6062
useChatState();
6163

6264
if (props.inline) return null;
6365

66+
const clear = () => {
67+
clearConversation();
68+
resetHeight();
69+
};
70+
6471
return (
6572
<div
6673
className={`tv-text-xs tv-rounded-md !tv-bg-transparent tv-flex !hover:bg-tv-zinc-200 tv-px-2 tv-justify-end tv-items-center tv-p-2 tv-gap-0.5 tv-cursor-pointer ${props.type}`}
6774
onClick={() =>
6875
messages.length < 1
6976
? setOpen(false)
7077
: isDoneReading
71-
? clearConversation()
78+
? clear()
7279
: stopGeneratingMessage()
7380
}
7481
>

clients/search-component/src/utils/hooks/useChatHeight.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { useEffect, useState } from "react";
1+
import { atom, useAtom } from "jotai";
2+
import { useEffect } from "react";
3+
4+
const chatHeightAtom = atom<number>(0);
5+
const enabledAtom = atom<boolean>(true);
6+
const minHeightAtom = atom<number>(0);
27

38
export const useChatHeight = (
4-
modalRef: React.RefObject<HTMLDivElement>,
5-
absoluteMinimum: number = 0
9+
modalRef?: React.RefObject<HTMLDivElement>,
10+
absoluteMinimum: number = 0,
611
) => {
7-
const [chatHeight, setChatHeight] = useState(absoluteMinimum);
8-
const [minHeight, setMinHeight] = useState(absoluteMinimum);
9-
const [enabled, setEnabled] = useState(true);
12+
const [minHeight, setMinHeight] = useAtom(minHeightAtom);
13+
const [chatHeight, setChatHeight] = useAtom(chatHeightAtom);
14+
const [enabled, setEnabled] = useAtom(enabledAtom);
1015

1116
useEffect(() => {
17+
if (!modalRef) {
18+
return;
19+
}
1220
const ref = modalRef.current;
1321
if (ref) {
1422
const observer = new ResizeObserver((entries) => {

0 commit comments

Comments
 (0)