Resolve reduce a rendering performance

This commit is contained in:
Faisal Amir 2023-11-13 15:08:42 +07:00
parent 5a197f1e73
commit d6c463674d

View File

@ -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 { Model } from '@janhq/core/lib/types'
import { Button, Badge, Textarea } from '@janhq/uikit' import { Button, Badge, Textarea } from '@janhq/uikit'
@ -55,6 +55,9 @@ const ChatScreen = () => {
const { getUserConversations } = useGetUserConversations() const { getUserConversations } = useGetUserConversations()
const conversations = useAtomValue(userConversationsAtom) const conversations = useAtomValue(userConversationsAtom)
const isEnableChat = (currentConvo && activeModel) || conversations.length > 0 const isEnableChat = (currentConvo && activeModel) || conversations.length > 0
const [isModelAvailable, setIsModelAvailable] = useState(
downloadedModels.filter((x) => x.name === currentConvo?.name).length === 0
)
const textareaRef = useRef<HTMLTextAreaElement>(null) const textareaRef = useRef<HTMLTextAreaElement>(null)
@ -67,6 +70,13 @@ const ChatScreen = () => {
setCurrentPrompt(e.target.value) 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 () => { const handleSendMessage = async () => {
if (activeConversationId) { if (activeConversationId) {
sendChatMessage() sendChatMessage()
@ -126,8 +136,7 @@ const ChatScreen = () => {
).length === 0 && '-mt-1' ).length === 0 && '-mt-1'
)} )}
> >
{downloadedModels.filter((x) => x.name === currentConvo?.name) {isModelAvailable && (
.length === 0 && (
<Button <Button
themes="secondary" themes="secondary"
size="sm" size="sm"