fix: title thread not updated on input edit title (#3148)

This commit is contained in:
Faisal Amir 2024-07-09 21:18:55 +07:00 committed by Louis
parent eac415aeca
commit b28a9766b9
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -1,4 +1,4 @@
import { useCallback, memo, useState } from 'react' import { useCallback, useLayoutEffect, memo, useState } from 'react'
import { Thread } from '@janhq/core' import { Thread } from '@janhq/core'
import { Modal, ModalClose, Button, Input } from '@janhq/joi' import { Modal, ModalClose, Button, Input } from '@janhq/joi'
@ -13,9 +13,14 @@ type Props = {
const ModalEditTitleThread = ({ thread, closeContextMenu }: Props) => { const ModalEditTitleThread = ({ thread, closeContextMenu }: Props) => {
const [title, setTitle] = useState(thread.title) const [title, setTitle] = useState(thread.title)
const { updateThreadMetadata } = useCreateNewThread() const { updateThreadMetadata } = useCreateNewThread()
useLayoutEffect(() => {
if (thread.title) {
setTitle(thread.title)
}
}, [thread.title])
const onUpdateTitle = useCallback( const onUpdateTitle = useCallback(
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.stopPropagation() e.stopPropagation()