refactor: delete unused search space hooks and update exports

This commit is contained in:
CREDO23 2025-12-12 09:20:52 +00:00
parent 291bb0369a
commit ae1cd09013
3 changed files with 0 additions and 137 deletions

View file

@ -1,5 +1,4 @@
export * from "./use-logs";
export * from "./use-rbac";
export * from "./use-search-source-connectors";
export * from "./use-search-space";
export * from "./use-user";

View file

@ -1,60 +0,0 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { authenticatedFetch } from "@/lib/auth-utils";
interface SearchSpace {
created_at: string;
id: number;
name: string;
description: string;
user_id: string;
citations_enabled: boolean;
qna_custom_instructions: string | null;
}
interface UseSearchSpaceOptions {
searchSpaceId: string | number;
autoFetch?: boolean;
}
export function useSearchSpace({ searchSpaceId, autoFetch = true }: UseSearchSpaceOptions) {
const [searchSpace, setSearchSpace] = useState<SearchSpace | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchSearchSpace = useCallback(async () => {
try {
// Only run on client-side
if (typeof window === "undefined") return;
setLoading(true);
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces/${searchSpaceId}`,
{ method: "GET" }
);
if (!response.ok) {
throw new Error(`Failed to fetch search space: ${response.status}`);
}
const data = await response.json();
setSearchSpace(data);
setError(null);
} catch (err: any) {
setError(err.message || "Failed to fetch search space");
console.error("Error fetching search space:", err);
} finally {
setLoading(false);
}
}, [searchSpaceId]);
useEffect(() => {
if (autoFetch) {
fetchSearchSpace();
}
}, [autoFetch, fetchSearchSpace]);
return { searchSpace, loading, error, fetchSearchSpace };
}

View file

@ -1,76 +0,0 @@
"use client";
import { useEffect, useState } from "react";
import { toast } from "sonner";
import { authenticatedFetch } from "@/lib/auth-utils";
interface SearchSpace {
id: number;
name: string;
description: string;
created_at: string;
citations_enabled: boolean;
qna_custom_instructions: string | null;
member_count: number;
is_owner: boolean;
}
export function useSearchSpaces() {
const [searchSpaces, setSearchSpaces] = useState<SearchSpace[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchSearchSpaces = async () => {
try {
setLoading(true);
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces`,
{ method: "GET" }
);
if (!response.ok) {
toast.error("Failed to fetch search spaces");
throw new Error("Failed to fetch search spaces");
}
const data = await response.json();
setSearchSpaces(data);
setError(null);
} catch (err: any) {
setError(err.message || "Failed to fetch search spaces");
console.error("Error fetching search spaces:", err);
} finally {
setLoading(false);
}
};
fetchSearchSpaces();
}, []);
// Function to refresh the search spaces list
const refreshSearchSpaces = async () => {
setLoading(true);
try {
const response = await authenticatedFetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces`,
{ method: "GET" }
);
if (!response.ok) {
toast.error("Failed to fetch search spaces");
throw new Error("Failed to fetch search spaces");
}
const data = await response.json();
setSearchSpaces(data);
setError(null);
} catch (err: any) {
setError(err.message || "Failed to fetch search spaces");
} finally {
setLoading(false);
}
};
return { searchSpaces, loading, error, refreshSearchSpaces };
}