-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: edit title thread * fix: fix copies * fix copies * fix copies
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
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
71 changes: 71 additions & 0 deletions
71
web/screens/Thread/ThreadLeftPanel/ModalEditTitleThread/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,71 @@ | ||
import { useCallback, memo, useState } from 'react' | ||
|
||
import { Thread } from '@janhq/core' | ||
import { Modal, ModalClose, Button, Input } from '@janhq/joi' | ||
import { PencilIcon } from 'lucide-react' | ||
|
||
import { useCreateNewThread } from '@/hooks/useCreateNewThread' | ||
|
||
type Props = { | ||
thread: Thread | ||
} | ||
|
||
const ModalEditTitleThread = ({ thread }: Props) => { | ||
const [title, setTitle] = useState(thread.title) | ||
|
||
const { updateThreadMetadata } = useCreateNewThread() | ||
|
||
const onUpdateTitle = useCallback( | ||
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
e.stopPropagation() | ||
|
||
updateThreadMetadata({ | ||
...thread, | ||
title: title || 'New Thread', | ||
}) | ||
}, | ||
[thread, title, updateThreadMetadata] | ||
) | ||
|
||
return ( | ||
<Modal | ||
title="Edit title thread" | ||
trigger={ | ||
<div | ||
className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-[hsla(var(--dropdown-menu-hover-bg))]" | ||
onClick={(e) => e.stopPropagation()} | ||
> | ||
<PencilIcon size={16} className="text-[hsla(var(--secondary))]" /> | ||
<span className="text-bold text-[hsla(var(--secondary))]"> | ||
Edit title | ||
</span> | ||
</div> | ||
} | ||
content={ | ||
<form className="mt-4"> | ||
<Input | ||
value={title} | ||
onChange={(e) => setTitle(e.target.value)} | ||
autoFocus | ||
/> | ||
<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 | ||
type="submit" | ||
onClick={onUpdateTitle} | ||
disabled={title.length === 0} | ||
> | ||
Save | ||
</Button> | ||
</ModalClose> | ||
</div> | ||
</form> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
export default memo(ModalEditTitleThread) |
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