@@ -3,7 +3,7 @@ import { Fragment, useEffect } from 'react'
33import { Model } from '@janhq/core/lib/types'
44import { ScrollArea , Input , Button , Badge } from '@janhq/uikit'
55
6- import { useAtom , useAtomValue , useSetAtom } from 'jotai'
6+ import { useAtom , useAtomValue } from 'jotai'
77import { Trash2Icon } from 'lucide-react'
88
99import { currentPromptAtom } from '@/containers/Providers/Jotai'
@@ -17,6 +17,7 @@ import useDeleteConversation from '@/hooks/useDeleteConversation'
1717
1818import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
1919
20+ import useGetUserConversations from '@/hooks/useGetUserConversations'
2021import { useMainViewState } from '@/hooks/useMainViewState'
2122
2223import useSendChatMessage from '@/hooks/useSendChatMessage'
@@ -28,6 +29,7 @@ import HistoryList from '@/screens/Chat/HistoryList'
2829import {
2930 currentConversationAtom ,
3031 getActiveConvoIdAtom ,
32+ userConversationsAtom ,
3133 waitingToSendMessage ,
3234} from '@/helpers/atoms/Conversation.atom'
3335
@@ -40,7 +42,6 @@ const ChatScreen = () => {
4042 const { activeModel, stateModel } = useActiveModel ( )
4143 const { setMainViewState } = useMainViewState ( )
4244
43- const isEnableChat = currentConvo && activeModel
4445 const [ currentPrompt , setCurrentPrompt ] = useAtom ( currentPromptAtom )
4546 const currentConvoState = useAtomValue ( currentConvoStateAtom )
4647 const { sendChatMessage } = useSendChatMessage ( )
@@ -49,6 +50,14 @@ const ChatScreen = () => {
4950 const activeConversationId = useAtomValue ( getActiveConvoIdAtom )
5051 const [ isWaitingToSend , setIsWaitingToSend ] = useAtom ( waitingToSendMessage )
5152 const { requestCreateConvo } = useCreateConversation ( )
53+ const { getUserConversations } = useGetUserConversations ( )
54+ const conversations = useAtomValue ( userConversationsAtom )
55+ const isEnableChat = ( currentConvo && activeModel ) || conversations . length > 0
56+
57+ useEffect ( ( ) => {
58+ getUserConversations ( )
59+ // eslint-disable-next-line react-hooks/exhaustive-deps
60+ } , [ ] )
5261
5362 const handleMessageChange = ( value : string ) => {
5463 setCurrentPrompt ( value )
@@ -81,6 +90,8 @@ const ChatScreen = () => {
8190 }
8291 }
8392
93+ console . log ( currentConvo )
94+
8495 return (
8596 < div className = "flex h-full" >
8697 < div className = "flex h-full w-64 flex-shrink-0 flex-col border-r border-border" >
@@ -91,14 +102,34 @@ const ChatScreen = () => {
91102 < div className = "relative flex h-full w-full flex-col bg-muted/10" >
92103 < div className = "flex h-full w-full flex-col justify-between" >
93104 { isEnableChat && (
94- < div className = "h-[53px] flex-shrink-0 border-b border-border p-4" >
105+ < div className = "h-[53px] flex-shrink-0 border-b border-border bg-background p-4" >
95106 < div className = "flex items-center justify-between" >
96107 < span > { currentConvo ?. name ?? '' } </ span >
97- < Trash2Icon
98- size = { 16 }
99- className = "cursor-pointer text-muted-foreground"
100- onClick = { ( ) => deleteConvo ( ) }
101- />
108+ { downloadedModels . find ( ( x ) => x . name === currentConvo ?. name ) ||
109+ activeModel ?. _id === currentConvo ?. modelId ? (
110+ < Fragment >
111+ { ! stateModel . loading && (
112+ < Trash2Icon
113+ size = { 16 }
114+ className = "cursor-pointer text-muted-foreground"
115+ onClick = { ( ) => deleteConvo ( ) }
116+ />
117+ ) }
118+ </ Fragment >
119+ ) : (
120+ < div >
121+ < Button
122+ themes = "secondary"
123+ size = "sm"
124+ className = "-mt-1"
125+ onClick = { ( ) => {
126+ setMainViewState ( MainViewState . ExploreModels )
127+ } }
128+ >
129+ Download Model
130+ </ Button >
131+ </ div >
132+ ) }
102133 </ div >
103134 </ div >
104135 ) }
@@ -140,7 +171,11 @@ const ChatScreen = () => {
140171 className = "h-10"
141172 onKeyDown = { ( e ) => handleKeyDown ( e ) }
142173 placeholder = "Type your message ..."
143- disabled = { ! activeModel || stateModel . loading }
174+ disabled = {
175+ ! activeModel ||
176+ stateModel . loading ||
177+ activeModel . _id !== currentConvo ?. modelId
178+ }
144179 value = { currentPrompt }
145180 onChange = { ( e ) => handleMessageChange ( e . target . value ) }
146181 />
0 commit comments