chore: import upstream snapshot with attribution
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import {
|
||||
resumeThreadErrorState,
|
||||
useChatInteract,
|
||||
useChatSession,
|
||||
useConfig
|
||||
} from '@chainlit/react-client';
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default function AutoResumeThread({ id }: Props) {
|
||||
const navigate = useNavigate();
|
||||
const { config } = useConfig();
|
||||
const { clear, setIdToResume } = useChatInteract();
|
||||
const { session, idToResume } = useChatSession();
|
||||
const [resumeThreadError, setResumeThreadError] = useRecoilState(
|
||||
resumeThreadErrorState
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!config?.threadResumable) return;
|
||||
clear();
|
||||
setIdToResume(id);
|
||||
if (!config?.dataPersistence) {
|
||||
navigate('/');
|
||||
}
|
||||
}, [config?.threadResumable, id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (id !== idToResume) {
|
||||
return;
|
||||
}
|
||||
if (session?.error) {
|
||||
toast.error("Couldn't resume chat");
|
||||
navigate('/');
|
||||
}
|
||||
}, [session, idToResume, id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (resumeThreadError) {
|
||||
toast.error("Couldn't resume chat: " + resumeThreadError);
|
||||
navigate('/');
|
||||
setResumeThreadError(undefined);
|
||||
}
|
||||
}, [resumeThreadError]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user