Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate, useParams } from "@tanstack/react-router";
import { useMatchRoute, useNavigate } from "@tanstack/react-router";
import { navigateToV2Workspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";
import { getFlattenedV2WorkspaceIds } from "../../utils/getFlattenedV2WorkspaceIds";
Expand All @@ -11,13 +11,19 @@ import { getFlattenedV2WorkspaceIds } from "../../utils/getFlattenedV2WorkspaceI
*/
export function useNavigateAwayFromWorkspace() {
const navigate = useNavigate();
const params = useParams({ strict: false });
const matchRoute = useMatchRoute();
const collections = useCollections();

return (workspaceId: string) => {
if (params.workspaceId !== workspaceId) return;
const ids = getFlattenedV2WorkspaceIds(collections);
const next = ids.find((id) => id !== workspaceId);
const isViewingWorkspace = !!matchRoute({
to: "/v2-workspace/$workspaceId",
params: { workspaceId },
fuzzy: true,
});
if (!isViewingWorkspace) return;
const next = getFlattenedV2WorkspaceIds(collections).find(
(id) => id !== workspaceId,
);
if (next) {
void navigateToV2Workspace(next, navigate);
} else {
Expand Down
Loading