ui: reset kai thread on site change
This commit is contained in:
parent
9fec22319b
commit
04beacde61
1 changed files with 17 additions and 10 deletions
|
|
@ -24,20 +24,19 @@ function KaiChat() {
|
||||||
const [initialMsg, setInitialMsg] = React.useState<string | null>(null);
|
const [initialMsg, setInitialMsg] = React.useState<string | null>(null);
|
||||||
const { showModal, hideModal } = useModal();
|
const { showModal, hideModal } = useModal();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const params = new URLSearchParams(location.search);
|
|
||||||
const threadIdFromUrl = params.get('threadId');
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Reset chat state and clear URL params when project changes
|
|
||||||
setSection('intro');
|
|
||||||
setThreadId(null);
|
|
||||||
history.replace({ search: '' });
|
history.replace({ search: '' });
|
||||||
}, [activeSiteId]);
|
setThreadId(null);
|
||||||
|
setSection('intro');
|
||||||
|
setInitialMsg(null);
|
||||||
|
setTitle(null);
|
||||||
|
}, [activeSiteId, history]);
|
||||||
|
|
||||||
const openChats = () => {
|
const openChats = () => {
|
||||||
showModal(
|
showModal(
|
||||||
<ChatsModal
|
<ChatsModal
|
||||||
projectId={activeSiteId}
|
projectId={activeSiteId!}
|
||||||
onSelect={(threadId: string, title: string) => {
|
onSelect={(threadId: string, title: string) => {
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
setThreadId(threadId);
|
setThreadId(threadId);
|
||||||
|
|
@ -49,11 +48,19 @@ function KaiChat() {
|
||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (
|
||||||
|
activeSiteId &&
|
||||||
|
parseInt(activeSiteId, 10) !== parseInt(location.pathname.split('/')[1], 10)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
const threadIdFromUrl = params.get('threadId');
|
||||||
if (threadIdFromUrl) {
|
if (threadIdFromUrl) {
|
||||||
setThreadId(threadIdFromUrl);
|
setThreadId(threadIdFromUrl);
|
||||||
setSection('chat');
|
setSection('chat');
|
||||||
}
|
}
|
||||||
}, [threadIdFromUrl]);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (threadId) {
|
if (threadId) {
|
||||||
|
|
@ -138,14 +145,14 @@ function ChatsModal({
|
||||||
isPending,
|
isPending,
|
||||||
refetch,
|
refetch,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['kai', 'chats'],
|
queryKey: ['kai', 'chats', projectId],
|
||||||
queryFn: () => kaiService.getKaiChats(projectId),
|
queryFn: () => kaiService.getKaiChats(projectId),
|
||||||
staleTime: 1000 * 60,
|
staleTime: 1000 * 60,
|
||||||
});
|
});
|
||||||
|
|
||||||
const onDelete = async (id: string) => {
|
const onDelete = async (id: string) => {
|
||||||
try {
|
try {
|
||||||
await kaiService.deleteKaiChat(projectId, userId, id);
|
await kaiService.deleteKaiChat(projectId, id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error("Something wen't wrong. Please try again later.");
|
toast.error("Something wen't wrong. Please try again later.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue