-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add delete all threads * add testcase * add testcase * fix lint * fix linter * fix linter * change position Delete All Threads
- Loading branch information
Showing
6 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
web/screens/Thread/ThreadLeftPanel/ModalDeleteAllThreads/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useCallback, memo } from 'react' | ||
|
||
import { Modal, ModalClose, Button } from '@janhq/joi' | ||
|
||
import { useAtom, useAtomValue } from 'jotai' | ||
|
||
import useDeleteThread from '@/hooks/useDeleteThread' | ||
|
||
import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom' | ||
|
||
import { | ||
modalActionThreadAtom, | ||
ThreadModalAction, | ||
threadsAtom, | ||
} from '@/helpers/atoms/Thread.atom' | ||
|
||
const ModalDeleteAllThreads = () => { | ||
const { deleteAllThreads } = useDeleteThread() | ||
const [modalActionThread, setModalActionThread] = useAtom( | ||
modalActionThreadAtom | ||
) | ||
const [threads] = useAtom(threadsAtom) | ||
const janDataFolderPath = useAtomValue(janDataFolderPathAtom) | ||
|
||
const onDeleteAllThreads = useCallback( | ||
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
e.stopPropagation() | ||
deleteAllThreads(threads) | ||
}, | ||
[deleteAllThreads, threads] | ||
) | ||
|
||
const onCloseModal = useCallback(() => { | ||
setModalActionThread({ | ||
showModal: undefined, | ||
thread: undefined, | ||
}) | ||
}, [setModalActionThread]) | ||
|
||
return ( | ||
<Modal | ||
title="Delete All Threads" | ||
onOpenChange={onCloseModal} | ||
open={modalActionThread.showModal === ThreadModalAction.DeleteAll} | ||
content={ | ||
<div> | ||
<p className="text-[hsla(var(--text-secondary))]"> | ||
Are you sure you want to delete all chat history? This will remove{' '} | ||
all {threads.length} conversation threads in{' '} | ||
<span className="font-mono">{janDataFolderPath}\threads</span> and | ||
cannot be undone. | ||
</p> | ||
<div className="mt-4 flex justify-end gap-x-2"> | ||
<ModalClose asChild onClick={(e) => e.stopPropagation()}> | ||
<Button theme="ghost">Cancel</Button> | ||
</ModalClose> | ||
<ModalClose asChild> | ||
<Button | ||
autoFocus | ||
theme="destructive" | ||
onClick={onDeleteAllThreads} | ||
> | ||
Delete | ||
</Button> | ||
</ModalClose> | ||
</div> | ||
</div> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
export default memo(ModalDeleteAllThreads) |