Skip to content

Commit

Permalink
fix: stop streaming while delete and clean thread
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 5, 2024
1 parent 51f8d01 commit 370f0c4
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions web/screens/Chat/ThreadList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ModalTrigger,
ModalClose,
ModalFooter,
ModalPortal,
ModalContent,
ModalHeader,
ModalTitle,
Expand Down Expand Up @@ -34,7 +35,6 @@ import useThreads from '@/hooks/useThreads'

import { displayDate } from '@/utils/datetime'

import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
import {
activeThreadAtom,
threadStatesAtom,
Expand All @@ -50,7 +50,6 @@ export default function ThreadList() {
const activeThread = useAtomValue(activeThreadAtom)
const { deleteThread, cleanThread } = useDeleteThread()
const { downloadedModels } = useGetDownloadedModels()
const messages = useAtomValue(getCurrentChatMessagesAtom)

const { activeThreadId, setActiveThread: onThreadClick } =
useSetActiveThread()
Expand Down Expand Up @@ -93,12 +92,8 @@ export default function ThreadList() {
`group/message relative mb-1 flex cursor-pointer flex-col transition-all hover:rounded-lg hover:bg-gray-100 hover:dark:bg-secondary/50`
)}
onClick={() => {
if (
messages[messages.length - 1]?.status !==
MessageStatus.Pending
) {
onThreadClick(thread)
}
console.log('a')
onThreadClick(thread)
}}
>
<div className="relative z-10 p-4 py-4">
Expand All @@ -121,7 +116,7 @@ export default function ThreadList() {
<MoreVerticalIcon />
<div className="invisible absolute right-0 z-20 w-40 overflow-hidden rounded-lg border border-border bg-background shadow-lg group-hover/icon:visible">
<Modal>
<ModalTrigger asChild>
<ModalTrigger asChild onClick={(e) => e.stopPropagation()}>
<div className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-secondary">
<Paintbrush
size={16}
Expand All @@ -132,20 +127,27 @@ export default function ThreadList() {
</span>
</div>
</ModalTrigger>
<ModalPortal />
<ModalContent>
<ModalHeader>
<ModalTitle>Clean Thread</ModalTitle>
</ModalHeader>
<p>Are you sure you want to clean this thread?</p>
<ModalFooter>
<div className="flex gap-x-2">
<ModalClose asChild>
<ModalClose
asChild
onClick={(e) => e.stopPropagation()}
>
<Button themes="ghost">No</Button>
</ModalClose>
<ModalClose asChild>
<Button
themes="danger"
onClick={() => cleanThread(thread.id)}
onClick={(e) => {
e.stopPropagation()
cleanThread(thread.id)
}}
autoFocus
>
Yes
Expand All @@ -155,9 +157,8 @@ export default function ThreadList() {
</ModalFooter>
</ModalContent>
</Modal>

<Modal>
<ModalTrigger asChild>
<ModalTrigger asChild onClick={(e) => e.stopPropagation()}>
<div className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-secondary">
<Trash2Icon
size={16}
Expand All @@ -168,6 +169,7 @@ export default function ThreadList() {
</span>
</div>
</ModalTrigger>
<ModalPortal />
<ModalContent>
<ModalHeader>
<ModalTitle>Delete Thread</ModalTitle>
Expand All @@ -178,14 +180,20 @@ export default function ThreadList() {
</p>
<ModalFooter>
<div className="flex gap-x-2">
<ModalClose asChild>
<ModalClose
asChild
onClick={(e) => e.stopPropagation()}
>
<Button themes="ghost">No</Button>
</ModalClose>
<ModalClose asChild>
<Button
autoFocus
themes="danger"
onClick={() => deleteThread(thread.id)}
onClick={(e) => {
e.stopPropagation()
deleteThread(thread.id)
}}
>
Yes
</Button>
Expand Down

0 comments on commit 370f0c4

Please sign in to comment.