Transition to single chat url once the first answer is delivered
This commit is contained in:
parent
d85d9f164b
commit
83a8620462
1 changed files with 8 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import { toast } from 'sonner';
|
||||||
import { useSearchParams } from 'next/navigation';
|
import { useSearchParams } from 'next/navigation';
|
||||||
import { getSuggestions } from '@/lib/actions';
|
import { getSuggestions } from '@/lib/actions';
|
||||||
import Error from 'next/error';
|
import Error from 'next/error';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
export type Message = {
|
export type Message = {
|
||||||
messageId: string;
|
messageId: string;
|
||||||
|
|
@ -283,6 +284,8 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||||
|
|
||||||
const [notFound, setNotFound] = useState(false);
|
const [notFound, setNotFound] = useState(false);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
chatId &&
|
chatId &&
|
||||||
|
|
@ -420,6 +423,11 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.type === 'messageEnd') {
|
if (data.type === 'messageEnd') {
|
||||||
|
if (!chatHistory.length) {
|
||||||
|
const url = `/c/${chatId}`;
|
||||||
|
router.replace(url);
|
||||||
|
}
|
||||||
|
|
||||||
setChatHistory((prevHistory) => [
|
setChatHistory((prevHistory) => [
|
||||||
...prevHistory,
|
...prevHistory,
|
||||||
['human', message],
|
['human', message],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue