refactor: remove frontend auto-create search space logic

- Removed auto-creation of default search space from frontend dashboard
- Frontend now only handles auto-redirect for users with exactly 1 search space
- All default search space creation should be handled by backend on_after_register
This commit is contained in:
CREDO23 2026-01-09 14:47:00 +02:00
parent 1d3fd8d47c
commit a099bcf5fb

View file

@ -7,11 +7,8 @@ import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useEffect, useRef, useState } from "react";
import {
createSearchSpaceMutationAtom,
deleteSearchSpaceMutationAtom,
} from "@/atoms/search-spaces/search-space-mutation.atoms";
import { useEffect } from "react";
import { deleteSearchSpaceMutationAtom } from "@/atoms/search-spaces/search-space-mutation.atoms";
import { searchSpacesAtom } from "@/atoms/search-spaces/search-space-query.atoms";
import { currentUserAtom } from "@/atoms/user/user-query.atoms";
import { Logo } from "@/components/Logo";
@ -135,10 +132,6 @@ const DashboardPage = () => {
const tCommon = useTranslations("common");
const router = useRouter();
// State for auto-creating search space
const [isAutoCreating, setIsAutoCreating] = useState(false);
const hasAttemptedAutoCreate = useRef(false);
// Animation variants
const containerVariants: Variants = {
hidden: { opacity: 0 },
@ -170,44 +163,17 @@ const DashboardPage = () => {
refetch: refreshSearchSpaces,
} = useAtomValue(searchSpacesAtom);
const { mutateAsync: deleteSearchSpace } = useAtomValue(deleteSearchSpaceMutationAtom);
const { mutateAsync: createSearchSpace } = useAtomValue(createSearchSpaceMutationAtom);
const { data: user, isPending: isLoadingUser, error: userError } = useAtomValue(currentUserAtom);
// Auto-redirect to chat for users with exactly 1 search space, or auto-create if none
// Auto-redirect to chat for users with exactly 1 search space
useEffect(() => {
const handleAutoRedirect = async () => {
if (loading || hasAttemptedAutoCreate.current) return;
if (loading) return;
if (searchSpaces.length === 1) {
router.replace(`/dashboard/${searchSpaces[0].id}/new-chat`);
return;
}
if (searchSpaces.length > 1) {
return;
}
hasAttemptedAutoCreate.current = true;
setIsAutoCreating(true);
try {
const newSearchSpace = await createSearchSpace({
name: "My Search Space",
description: "Your personal search space",
});
router.replace(`/dashboard/${newSearchSpace.id}/new-chat`);
} catch (err) {
console.error("Failed to auto-create search space:", err);
setIsAutoCreating(false);
}
};
handleAutoRedirect();
}, [loading, searchSpaces, router, createSearchSpace]);
if (searchSpaces.length === 1) {
router.replace(`/dashboard/${searchSpaces[0].id}/new-chat`);
}
}, [loading, searchSpaces, router]);
// Create user object for UserDropdown
const customUser = {
@ -218,8 +184,8 @@ const DashboardPage = () => {
avatar: "/icon-128.png", // Default avatar
};
// Show loading while loading, auto-redirecting (single search space), or auto-creating
if (loading || isAutoCreating || (searchSpaces.length === 1 && !error)) return <LoadingScreen />;
// Show loading while loading or auto-redirecting (single search space)
if (loading || (searchSpaces.length === 1 && !error)) return <LoadingScreen />;
if (error) return <ErrorScreen message={error?.message || "Failed to load search spaces"} />;
const handleDeleteSearchSpace = async (id: number) => {