mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
auto-redirect only for single search space users
This commit is contained in:
parent
5151ba381e
commit
edc5f379d3
1 changed files with 9 additions and 5 deletions
|
|
@ -174,18 +174,22 @@ const DashboardPage = () => {
|
||||||
|
|
||||||
const { data: user, isPending: isLoadingUser, error: userError } = useAtomValue(currentUserAtom);
|
const { data: user, isPending: isLoadingUser, error: userError } = useAtomValue(currentUserAtom);
|
||||||
|
|
||||||
// Auto-redirect to chat or auto-create search space
|
// Auto-redirect to chat for users with exactly 1 search space, or auto-create if none
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleAutoRedirect = async () => {
|
const handleAutoRedirect = async () => {
|
||||||
// Don't run if still loading or already attempted
|
// Don't run if still loading or already attempted
|
||||||
if (loading || hasAttemptedAutoCreate.current) return;
|
if (loading || hasAttemptedAutoCreate.current) return;
|
||||||
|
|
||||||
// If user has search spaces, redirect to the first one's chat
|
// If user has exactly 1 search space, redirect to its chat
|
||||||
if (searchSpaces.length > 0) {
|
if (searchSpaces.length === 1) {
|
||||||
router.replace(`/dashboard/${searchSpaces[0].id}/new-chat`);
|
router.replace(`/dashboard/${searchSpaces[0].id}/new-chat`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (searchSpaces.length > 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If no search spaces exist (edge case for users who registered before this feature),
|
// If no search spaces exist (edge case for users who registered before this feature),
|
||||||
// auto-create one and redirect
|
// auto-create one and redirect
|
||||||
hasAttemptedAutoCreate.current = true;
|
hasAttemptedAutoCreate.current = true;
|
||||||
|
|
@ -215,8 +219,8 @@ const DashboardPage = () => {
|
||||||
avatar: "/icon-128.png", // Default avatar
|
avatar: "/icon-128.png", // Default avatar
|
||||||
};
|
};
|
||||||
|
|
||||||
// Show loading while loading, auto-redirecting, or auto-creating
|
// Show loading while loading, auto-redirecting (single search space), or auto-creating
|
||||||
if (loading || isAutoCreating || (searchSpaces.length > 0 && !error)) return <LoadingScreen />;
|
if (loading || isAutoCreating || (searchSpaces.length === 1 && !error)) return <LoadingScreen />;
|
||||||
if (error) return <ErrorScreen message={error?.message || "Failed to load search spaces"} />;
|
if (error) return <ErrorScreen message={error?.message || "Failed to load search spaces"} />;
|
||||||
|
|
||||||
const handleDeleteSearchSpace = async (id: number) => {
|
const handleDeleteSearchSpace = async (id: number) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue