Fix logic for deletion to automatically re-render the side pane

This commit is contained in:
sabaimran 2024-08-05 18:07:20 +05:30
parent 20d95dc45e
commit 998d08f155

View file

@ -4,6 +4,8 @@ import styles from "./sidePanel.module.css";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { mutate } from "swr";
import { UserProfile, useAuthenticatedData } from "@/app/common/auth"; import { UserProfile, useAuthenticatedData } from "@/app/common/auth";
import Link from "next/link"; import Link from "next/link";
import useSWR from "swr"; import useSWR from "swr";
@ -148,7 +150,10 @@ function deleteConversation(conversationId: string) {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}) })
.then((response) => response.json()) .then((response) => {
response.json();
mutate("/api/chat/sessions");
})
.then((data) => {}) .then((data) => {})
.catch((err) => { .catch((err) => {
console.error(err); console.error(err);
@ -553,19 +558,6 @@ function ChatSessionActionMenu(props: ChatSessionActionMenuProps) {
onClick={() => { onClick={() => {
deleteConversation(props.conversationId); deleteConversation(props.conversationId);
setIsDeleting(false); setIsDeleting(false);
var currConversationId = parseInt(
new URLSearchParams(window.location.search).get(
"conversationId",
) || "0",
);
//edge case for deleting current conversation
if (currConversationId === parseInt(props.conversationId)) {
window.location.href = "/";
}
//reload side panel
setTimeout(() => {
window.location.reload();
}, 1000);
}} }}
className="bg-rose-500 hover:bg-rose-600" className="bg-rose-500 hover:bg-rose-600"
> >