mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-05-02 17:07:13 +00:00
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: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
f8e91e1ffa
commit
426e2360b3
2 changed files with 19 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue