"use client"; import React from "react"; import { Loader2 } from "lucide-react"; import ExplorerLoading from "@/components/explorer/states/ExplorerLoading"; import ExplorerEmpty from "@/components/explorer/states/ExplorerEmpty"; import ExplorerError from "@/components/explorer/states/ExplorerError"; import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { sortSearchItems, SEARCH_RESULTS_SORT, } from "@/lib/frontend/search/resultsSorting"; import SearchResultsToolbar from "@/components/search/SearchResultsToolbar"; import SearchResultsTable from "@/components/search/SearchResultsTable"; export default function SearchResults({ branch, status, items, total, error, onRetry, nextCursor, onLoadMore, isLoadingMore, loadMoreError, needsBranchSelection = false, }) { const [sortMode, setSortMode] = React.useState(SEARCH_RESULTS_SORT.RELEVANCE); const sortedItems = React.useMemo(() => { return sortSearchItems(items, sortMode); }, [items, sortMode]); if (status === "idle") { if (needsBranchSelection) { return ( ); } return ( ); } if (status === "loading") { return ; } if (status === "error" && error) { // Validation errors are rendered in the SearchForm (near the inputs). // We avoid showing a second alert in the results. if (error.kind === "validation") { return ( ); } return ( ); } const list = Array.isArray(sortedItems) ? sortedItems : []; if (list.length === 0) { return ( ); } return (
{loadMoreError ? ( {loadMoreError.title} {loadMoreError.description} ) : null} {nextCursor ? (
) : null}
); }