forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 style(chat): auto send message from URL (lobehub#6497)
* ✨ feat(chat): auto send message from URL * introduce MessageFromUrl component
- Loading branch information
1 parent
81867c4
commit 30b2639
Showing
2 changed files
with
76 additions
and
39 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/MessageFromUrl.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,31 @@ | ||
'use client'; | ||
|
||
import { useSearchParams } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
import { useSendMessage } from '@/features/ChatInput/useSend'; | ||
import { useChatStore } from '@/store/chat'; | ||
|
||
const MessageFromUrl = () => { | ||
const updateInputMessage = useChatStore((s) => s.updateInputMessage); | ||
const { send: sendMessage } = useSendMessage(); | ||
const searchParams = useSearchParams(); | ||
|
||
useEffect(() => { | ||
const message = searchParams.get('message'); | ||
if (message) { | ||
// Remove message from URL | ||
const params = new URLSearchParams(searchParams.toString()); | ||
params.delete('message'); | ||
const newUrl = `${window.location.pathname}?${params.toString()}`; | ||
window.history.replaceState({}, '', newUrl); | ||
|
||
updateInputMessage(message); | ||
sendMessage(); | ||
} | ||
}, [searchParams, updateInputMessage, sendMessage]); | ||
|
||
return null; | ||
}; | ||
|
||
export default MessageFromUrl; |
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