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
Branches
Tags
No related merge requests found
...@@ -24,7 +24,7 @@ export default function ThreadItem({ ...@@ -24,7 +24,7 @@ export default function ThreadItem({
hasNext, hasNext,
ctrlPressed = false, ctrlPressed = false,
}) { }) {
const { slug } = useParams(); const { slug, threadSlug = null } = useParams();
const optionsContainer = useRef(null); const optionsContainer = useRef(null);
const [showOptions, setShowOptions] = useState(false); const [showOptions, setShowOptions] = useState(false);
const linkTo = !thread.slug const linkTo = !thread.slug
...@@ -142,6 +142,7 @@ export default function ThreadItem({ ...@@ -142,6 +142,7 @@ export default function ThreadItem({
thread={thread} thread={thread}
onRemove={onRemove} onRemove={onRemove}
close={() => setShowOptions(false)} close={() => setShowOptions(false)}
currentThreadSlug={threadSlug}
/> />
)} )}
</div> </div>
...@@ -151,7 +152,14 @@ export default function ThreadItem({ ...@@ -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); const menuRef = useRef(null);
// Ref menu options // Ref menu options
...@@ -227,6 +235,10 @@ function OptionsMenu({ containerRef, workspace, thread, onRemove, close }) { ...@@ -227,6 +235,10 @@ function OptionsMenu({ containerRef, workspace, thread, onRemove, close }) {
if (success) { if (success) {
showToast("Thread deleted successfully!", "success", { clear: true }); showToast("Thread deleted successfully!", "success", { clear: true });
onRemove(thread.id); onRemove(thread.id);
// Redirect if deleting the active thread
if (currentThreadSlug === thread.slug) {
window.location.href = paths.workspace.chat(workspace.slug);
}
return; return;
} }
}; };
......
...@@ -87,6 +87,11 @@ export default function ThreadContainer({ workspace }) { ...@@ -87,6 +87,11 @@ export default function ThreadContainer({ workspace }) {
const slugs = threads.filter((t) => t.deleted === true).map((t) => t.slug); const slugs = threads.filter((t) => t.deleted === true).map((t) => t.slug);
await Workspace.threads.deleteBulk(workspace.slug, slugs); await Workspace.threads.deleteBulk(workspace.slug, slugs);
setThreads((prev) => prev.filter((t) => !t.deleted)); 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) { function removeThread(threadId) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment