Skip to content
Snippets Groups Projects
Unverified Commit 426e2360 authored by Sean Hatfield's avatar Sean Hatfield Committed by GitHub
Browse files

Redirect to default thread on thread deletion (#2808)


* redirect to default thread on thread deletion

* reset submodule

* handle redirect on bulk delete thread

* redirect on bulk thread delete only if deleted thread is selected

* redirect only on single delete of active thread

* lint

* patch threadSlug for clarity

---------

Co-authored-by: default avatarTimothy Carambat <rambat1010@gmail.com>
parent f8e91e1f
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ export default function ThreadItem({
hasNext,
ctrlPressed = false,
}) {
const { slug } = useParams();
const { slug, threadSlug = null } = useParams();
const optionsContainer = useRef(null);
const [showOptions, setShowOptions] = useState(false);
const linkTo = !thread.slug
......@@ -142,6 +142,7 @@ export default function ThreadItem({
thread={thread}
onRemove={onRemove}
close={() => setShowOptions(false)}
currentThreadSlug={threadSlug}
/>
)}
</div>
......@@ -151,7 +152,14 @@ export default function ThreadItem({
);
}
function OptionsMenu({ containerRef, workspace, thread, onRemove, close }) {
function OptionsMenu({
containerRef,
workspace,
thread,
onRemove,
close,
currentThreadSlug,
}) {
const menuRef = useRef(null);
// Ref menu options
......@@ -227,6 +235,10 @@ function OptionsMenu({ containerRef, workspace, thread, onRemove, close }) {
if (success) {
showToast("Thread deleted successfully!", "success", { clear: true });
onRemove(thread.id);
// Redirect if deleting the active thread
if (currentThreadSlug === thread.slug) {
window.location.href = paths.workspace.chat(workspace.slug);
}
return;
}
};
......
......@@ -87,6 +87,11 @@ export default function ThreadContainer({ workspace }) {
const slugs = threads.filter((t) => t.deleted === true).map((t) => t.slug);
await Workspace.threads.deleteBulk(workspace.slug, slugs);
setThreads((prev) => prev.filter((t) => !t.deleted));
// Only redirect if current thread is being deleted
if (slugs.includes(threadSlug)) {
window.location.href = paths.workspace.chat(workspace.slug);
}
};
function removeThread(threadId) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment