Skip to content

Commit ac1c701

Browse files
committed
Update convo state when user change model
1 parent 59ea9b3 commit ac1c701

File tree

9 files changed

+54
-24
lines changed

9 files changed

+54
-24
lines changed

uikit/src/button/styles.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
}
1313

1414
&-outline {
15-
@apply border-input hover:bg-accent hover:text-accent-foreground border bg-transparent;
15+
@apply border-input hover:bg-primary hover:text-primary-foreground border bg-transparent;
1616
}
1717

1818
&-secondary {
1919
@apply bg-secondary text-secondary-foreground hover:bg-secondary/80;
2020
}
2121

2222
&-ghost {
23-
@apply hover:bg-accent hover:text-accent-foreground;
23+
@apply hover:bg-primary hover:text-primary-foreground;
2424
}
2525

2626
&-sm {

uikit/src/command/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626

2727
&-list-item {
28-
@apply text-foreground aria-selected:bg-accent relative flex cursor-pointer select-none items-center rounded-md px-2 py-2 text-sm outline-none;
28+
@apply text-foreground aria-selected:bg-primary relative flex cursor-pointer select-none items-center rounded-md px-2 py-2 text-sm outline-none;
2929
}
3030

3131
&-empty {

uikit/src/main.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@
2727
}
2828
}
2929

30-
3130
:root {
3231
--background: 0 0% 100%;
3332
--foreground: 20 14.3% 4.1%;
3433

3534
--muted: 60 4.8% 95.9%;
3635
--muted-foreground: 240 3.8% 46.1%;
3736

38-
--accent: 60 4.8% 95.9%;
39-
--accent-foreground: 24 9.8% 10%;
40-
4137
--danger: 346.8 77.2% 49.8%;
4238
--danger-foreground: 355.7 100% 97.3%;
4339

@@ -77,9 +73,6 @@
7773
--muted: 12 6.5% 15.1%;
7874
--muted-foreground: 24 5.4% 63.9%;
7975

80-
--accent: 12 6.5% 15.1%;
81-
--accent-foreground: 60 9.1% 97.8%;
82-
8376
--danger: 346.8 77.2% 49.8%;
8477
--danger-foreground: 355.7 100% 97.3%;
8578

web/containers/Layout/TopBar/CommandListDownloadedModel/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function CommandListDownloadedModel() {
7373
<div className="flex w-full items-center justify-between">
7474
<span>{model.name}</span>
7575
{activeModel && activeModel._id === model._id && (
76-
<Badge>Active</Badge>
76+
<Badge themes="secondary">Active</Badge>
7777
)}
7878
</div>
7979
</CommandItem>

web/hooks/useGetConfiguredModels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function useGetConfiguredModels() {
4040
// TODO allow user for filter
4141
useEffect(() => {
4242
fetchModels()
43+
// eslint-disable-next-line react-hooks/exhaustive-deps
4344
}, [])
4445

4546
return { loading, models }

web/screens/Chat/HistoryList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react'
22

33
import { Conversation, Model } from '@janhq/core/lib/types'
4-
import { Button } from '@janhq/uikit'
4+
import { Badge, Button } from '@janhq/uikit'
55
import { motion as m } from 'framer-motion'
66
import { useAtomValue, useSetAtom } from 'jotai'
77

@@ -64,7 +64,7 @@ export default function HistoryList() {
6464
<div className="sticky top-0 z-20 flex flex-col border-b border-border bg-background px-4 py-3">
6565
<Button
6666
size="sm"
67-
themes="outline"
67+
themes="secondary"
6868
onClick={handleClickConversation}
6969
disabled={!activeModel}
7070
>

web/screens/Chat/index.tsx

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Fragment, useEffect } from 'react'
33
import { Model } from '@janhq/core/lib/types'
44
import { ScrollArea, Input, Button, Badge } from '@janhq/uikit'
55

6-
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
6+
import { useAtom, useAtomValue } from 'jotai'
77
import { Trash2Icon } from 'lucide-react'
88

99
import { currentPromptAtom } from '@/containers/Providers/Jotai'
@@ -17,6 +17,7 @@ import useDeleteConversation from '@/hooks/useDeleteConversation'
1717

1818
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
1919

20+
import useGetUserConversations from '@/hooks/useGetUserConversations'
2021
import { useMainViewState } from '@/hooks/useMainViewState'
2122

2223
import useSendChatMessage from '@/hooks/useSendChatMessage'
@@ -28,6 +29,7 @@ import HistoryList from '@/screens/Chat/HistoryList'
2829
import {
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
/>

web/screens/ExploreModels/ExploreModelList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function ExploreModelList(props: Props) {
1010
const { models } = props
1111
return (
1212
<div className="relative h-full w-full flex-shrink-0">
13-
{models?.map((item) => <ExploreModelItem key={item._id} model={item} />)}
13+
{models?.map((item, i) => <ExploreModelItem key={i} model={item} />)}
1414
</div>
1515
)
1616
}

web/screens/MyModels/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ const MyModelsScreen = () => {
113113
<Button
114114
themes="danger"
115115
onClick={() =>
116-
setTimeout(() => {
116+
setTimeout(async () => {
117+
await stopModel(model._id)
117118
deleteModel(model)
118119
}, 500)
119120
}

0 commit comments

Comments
 (0)