From d6c463674d44a6bad510228de73fdab061904611 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Mon, 13 Nov 2023 15:08:42 +0700 Subject: [PATCH] Resolve reduce a rendering performance --- web/screens/Chat/index.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/web/screens/Chat/index.tsx b/web/screens/Chat/index.tsx index 7c3aa2f28..01b2eae5f 100644 --- a/web/screens/Chat/index.tsx +++ b/web/screens/Chat/index.tsx @@ -1,4 +1,4 @@ -import { Fragment, useEffect, useRef } from 'react' +import { Fragment, useEffect, useRef, useState } from 'react' import { Model } from '@janhq/core/lib/types' import { Button, Badge, Textarea } from '@janhq/uikit' @@ -55,6 +55,9 @@ const ChatScreen = () => { const { getUserConversations } = useGetUserConversations() const conversations = useAtomValue(userConversationsAtom) const isEnableChat = (currentConvo && activeModel) || conversations.length > 0 + const [isModelAvailable, setIsModelAvailable] = useState( + downloadedModels.filter((x) => x.name === currentConvo?.name).length === 0 + ) const textareaRef = useRef(null) @@ -67,6 +70,13 @@ const ChatScreen = () => { setCurrentPrompt(e.target.value) } + useEffect(() => { + setIsModelAvailable( + downloadedModels.filter((x) => x.name === currentConvo?.name).length === 0 + ) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [currentConvo]) + const handleSendMessage = async () => { if (activeConversationId) { sendChatMessage() @@ -126,8 +136,7 @@ const ChatScreen = () => { ).length === 0 && '-mt-1' )} > - {downloadedModels.filter((x) => x.name === currentConvo?.name) - .length === 0 && ( + {isModelAvailable && (