UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

35 lines 1.22 kB
import { useCallback, useState } from "react"; import useProject from "../projects/useProject"; import useAxiosPrivate from "../../config/useAxiosPrivate"; import { handleError } from "../../utils/handleError"; export default function useSearchSpaces() { const { projectId } = useProject(); const axios = useAxiosPrivate(); const [results, setResults] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const search = useCallback(async ({ query, limit }) => { if (!projectId) return; if (!query.trim()) return; setLoading(true); setError(null); try { const response = await axios.post(`/${projectId}/search/spaces`, { query, limit }); setResults(response.data); } catch (err) { setError(handleError(err, "Failed to search spaces")); } finally { setLoading(false); } }, [projectId, axios]); const reset = useCallback(() => { setResults([]); setError(null); }, []); return { results, loading, error, search, reset }; } //# sourceMappingURL=useSearchSpaces.js.map