MCPcopy Create free account
hub / github.com/sqlchat/sqlchat / ConversationView

Function ConversationView

src/components/ConversationView/index.tsx:30–350  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28import { useTranslation } from "react-i18next";
29
30const ConversationView = () => {
31 const { data: session } = useSession();
32 const { t } = useTranslation();
33 const settingStore = useSettingStore();
34 const layoutStore = useLayoutStore();
35 const connectionStore = useConnectionStore();
36 const conversationStore = useConversationStore();
37 const userStore = useUserStore();
38 const messageStore = useMessageStore();
39 const [isStickyAtBottom, setIsStickyAtBottom] = useState<boolean>(true);
40 const [showHeaderShadow, setShowHeaderShadow] = useState<boolean>(false);
41 const conversationViewRef = useRef<HTMLDivElement>(null);
42 const currentConversation = conversationStore.getConversationById(conversationStore.currentConversationId);
43 const messageList = currentConversation
44 ? messageStore.messageList.filter((message: Message) => message.conversationId === currentConversation.id)
45 : [];
46 const lastMessage = last(messageList);
47 const [showSchemaDrawer, setShowSchemaDrawer] = useState<boolean>(false);
48
49 useEffect(() => {
50 messageStore.messageList.map((message: Message) => {
51 if (message.status === "LOADING") {
52 if (message.content === "") {
53 messageStore.updateMessage(message.id, {
54 content: "Failed to send the message.",
55 status: "FAILED",
56 });
57 } else {
58 messageStore.updateMessage(message.id, {
59 status: "DONE",
60 });
61 }
62 }
63 });
64
65 const handleConversationViewScroll = () => {
66 if (!conversationViewRef.current) {
67 return;
68 }
69 setShowHeaderShadow((conversationViewRef.current?.scrollTop || 0) > 0);
70 setIsStickyAtBottom(
71 conversationViewRef.current.scrollTop + conversationViewRef.current.clientHeight >= conversationViewRef.current.scrollHeight
72 );
73 };
74 conversationViewRef.current?.addEventListener("scroll", handleConversationViewScroll);
75
76 return () => {
77 conversationViewRef.current?.removeEventListener("scroll", handleConversationViewScroll);
78 };
79 }, []);
80
81 useEffect(() => {
82 if (!conversationViewRef.current) {
83 return;
84 }
85 conversationViewRef.current.scrollTop = conversationViewRef.current.scrollHeight;
86 }, [currentConversation, lastMessage?.id]);
87

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected