Skip to content

Commit

Permalink
Redirect to default thread on thread deletion (#2808)
Browse files Browse the repository at this point in the history
* 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: Timothy Carambat <[email protected]>
  • Loading branch information
shatfield4 and timothycarambat authored Dec 12, 2024
1 parent f8e91e1 commit 426e236
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,6 +142,7 @@ export default function ThreadItem({
thread={thread}
onRemove={onRemove}
close={() => setShowOptions(false)}
currentThreadSlug={threadSlug}
/>
)}
</div>
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 426e236

Please sign in to comment.