fix: reset inputs when reset conversation (#16233)

This commit is contained in:
Panpan 2025-03-20 00:17:58 +08:00 committed by GitHub
parent 106169ed7f
commit cade0f65e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -183,7 +183,10 @@ export const useEmbeddedChatbot = () => {
useEffect(() => { useEffect(() => {
// init inputs from url params // init inputs from url params
setInitInputs(getProcessedInputsFromUrlParams()) (async () => {
const inputs = await getProcessedInputsFromUrlParams()
setInitInputs(inputs)
})()
}, []) }, [])
useEffect(() => { useEffect(() => {
const conversationInputs: Record<string, any> = {} const conversationInputs: Record<string, any> = {}
@ -288,11 +291,11 @@ export const useEmbeddedChatbot = () => {
if (conversationId) if (conversationId)
setClearChatList(false) setClearChatList(false)
}, [handleConversationIdInfoChange, setClearChatList]) }, [handleConversationIdInfoChange, setClearChatList])
const handleNewConversation = useCallback(() => { const handleNewConversation = useCallback(async () => {
currentChatInstanceRef.current.handleStop() currentChatInstanceRef.current.handleStop()
setShowNewConversationItemInList(true) setShowNewConversationItemInList(true)
handleChangeConversation('') handleChangeConversation('')
handleNewConversationInputsChange({}) handleNewConversationInputsChange(await getProcessedInputsFromUrlParams())
setClearChatList(true) setClearChatList(true)
}, [handleChangeConversation, setShowNewConversationItemInList, handleNewConversationInputsChange, setClearChatList]) }, [handleChangeConversation, setShowNewConversationItemInList, handleNewConversationInputsChange, setClearChatList])

View File

@ -10,12 +10,14 @@ async function decodeBase64AndDecompress(base64String: string) {
return new TextDecoder().decode(decompressedArrayBuffer) return new TextDecoder().decode(decompressedArrayBuffer)
} }
function getProcessedInputsFromUrlParams(): Record<string, any> { async function getProcessedInputsFromUrlParams(): Promise<Record<string, any>> {
const urlParams = new URLSearchParams(window.location.search) const urlParams = new URLSearchParams(window.location.search)
const inputs: Record<string, any> = {} const inputs: Record<string, any> = {}
urlParams.forEach(async (value, key) => { await Promise.all(
inputs[key] = await decodeBase64AndDecompress(decodeURIComponent(value)) urlParams.entries().map(async ([key, value]) => {
}) inputs[key] = await decodeBase64AndDecompress(decodeURIComponent(value))
}),
)
return inputs return inputs
} }