mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
remove search client
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
import { unstable_cache } from "next/cache";
|
||||
import {
|
||||
getV2ListStoreAgents,
|
||||
getV2ListStoreCreators,
|
||||
} from "@/app/api/__generated__/endpoints/store/store";
|
||||
import { SearchResultsClient } from "./SearchResultsClient";
|
||||
import { StoreAgent, Creator } from "@/lib/autogpt-server-api";
|
||||
|
||||
// Cache the search results for 10 minutes based on search term and sort
|
||||
const getCachedSearchResults = unstable_cache(
|
||||
async (searchTerm: string, sort: string) => {
|
||||
try {
|
||||
const [agentsRes, creatorsRes] = await Promise.all([
|
||||
getV2ListStoreAgents({
|
||||
search_query: searchTerm,
|
||||
sorted_by: sort,
|
||||
}),
|
||||
getV2ListStoreCreators({
|
||||
search_query: searchTerm,
|
||||
}),
|
||||
]);
|
||||
|
||||
return {
|
||||
agents: ("agents" in agentsRes.data
|
||||
? agentsRes.data.agents || []
|
||||
: []) as StoreAgent[],
|
||||
creators: ("creators" in creatorsRes.data
|
||||
? creatorsRes.data.creators || []
|
||||
: []) as Creator[],
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching search results:", error);
|
||||
return {
|
||||
agents: [] as StoreAgent[],
|
||||
creators: [] as Creator[],
|
||||
};
|
||||
}
|
||||
},
|
||||
["marketplace-search"], // Cache key prefix
|
||||
{
|
||||
revalidate: 600, // 10 minutes
|
||||
tags: ["marketplace-search"],
|
||||
},
|
||||
);
|
||||
|
||||
export async function SearchResults({
|
||||
searchTerm,
|
||||
sort,
|
||||
}: {
|
||||
searchTerm: string;
|
||||
sort: string;
|
||||
}) {
|
||||
const { agents, creators } = await getCachedSearchResults(searchTerm, sort);
|
||||
|
||||
const agentsCount = agents.length;
|
||||
const creatorsCount = creators.length;
|
||||
const totalCount = agentsCount + creatorsCount;
|
||||
|
||||
if (totalCount === 0) {
|
||||
return (
|
||||
<div className="mt-20 flex flex-col items-center justify-center">
|
||||
<h3 className="mb-2 text-xl font-medium text-neutral-600 dark:text-neutral-300">
|
||||
No results found
|
||||
</h3>
|
||||
<p className="text-neutral-500 dark:text-neutral-400">
|
||||
Try adjusting your search terms or filters
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SearchResultsClient
|
||||
initialAgents={agents}
|
||||
initialCreators={creators}
|
||||
agentsCount={agentsCount}
|
||||
creatorsCount={creatorsCount}
|
||||
totalCount={totalCount}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useCallback } from "react";
|
||||
import { AgentsSection } from "@/components/agptui/composite/AgentsSection";
|
||||
import { FeaturedCreators } from "@/components/agptui/composite/FeaturedCreators";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { SearchFilterChips } from "@/components/agptui/SearchFilterChips";
|
||||
import { SortDropdown } from "@/components/agptui/SortDropdown";
|
||||
import { Creator, StoreAgent } from "@/lib/autogpt-server-api";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
export function SearchResultsClient({
|
||||
initialAgents,
|
||||
initialCreators,
|
||||
agentsCount,
|
||||
creatorsCount,
|
||||
totalCount,
|
||||
}: {
|
||||
initialAgents: StoreAgent[];
|
||||
initialCreators: Creator[];
|
||||
agentsCount: number;
|
||||
creatorsCount: number;
|
||||
totalCount: number;
|
||||
}) {
|
||||
const [showAgents, setShowAgents] = useState(true);
|
||||
const [showCreators, setShowCreators] = useState(true);
|
||||
const [agents, setAgents] = useState(initialAgents);
|
||||
const [creators, setCreators] = useState(initialCreators);
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const handleFilterChange = (value: string) => {
|
||||
if (value === "agents") {
|
||||
setShowAgents(true);
|
||||
setShowCreators(false);
|
||||
} else if (value === "creators") {
|
||||
setShowAgents(false);
|
||||
setShowCreators(true);
|
||||
} else {
|
||||
setShowAgents(true);
|
||||
setShowCreators(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSortChange = useCallback(
|
||||
(sortValue: string) => {
|
||||
// Update URL with new sort parameter to trigger server-side re-fetch
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set("sort", sortValue);
|
||||
router.push(`/marketplace/search?${params.toString()}`);
|
||||
|
||||
// Client-side sorting for immediate feedback
|
||||
let sortBy = "recent";
|
||||
if (sortValue === "runs") {
|
||||
sortBy = "runs";
|
||||
} else if (sortValue === "rating") {
|
||||
sortBy = "rating";
|
||||
}
|
||||
|
||||
const sortedAgents = [...agents].sort((a, b) => {
|
||||
if (sortBy === "runs") {
|
||||
return b.runs - a.runs;
|
||||
} else if (sortBy === "rating") {
|
||||
return b.rating - a.rating;
|
||||
} else {
|
||||
return (
|
||||
new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const sortedCreators = [...creators].sort((a, b) => {
|
||||
if (sortBy === "runs") {
|
||||
return b.agent_runs - a.agent_runs;
|
||||
} else if (sortBy === "rating") {
|
||||
return b.agent_rating - a.agent_rating;
|
||||
} else {
|
||||
// Creators don't have updated_at, sort by number of agents as fallback
|
||||
return b.num_agents - a.num_agents;
|
||||
}
|
||||
});
|
||||
|
||||
setAgents(sortedAgents);
|
||||
setCreators(sortedCreators);
|
||||
},
|
||||
[agents, creators, router, searchParams],
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mt-[36px] flex items-center justify-between">
|
||||
<SearchFilterChips
|
||||
totalCount={totalCount}
|
||||
agentsCount={agentsCount}
|
||||
creatorsCount={creatorsCount}
|
||||
onFilterChange={handleFilterChange}
|
||||
/>
|
||||
<SortDropdown onSort={handleSortChange} />
|
||||
</div>
|
||||
{/* Content section */}
|
||||
<div className="min-h-[500px] max-w-[1440px]">
|
||||
{showAgents && agentsCount > 0 && (
|
||||
<div className="mt-[36px]">
|
||||
<AgentsSection agents={agents} sectionTitle="Agents" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showAgents && agentsCount > 0 && creatorsCount > 0 && showCreators && (
|
||||
<Separator />
|
||||
)}
|
||||
{showCreators && creatorsCount > 0 && (
|
||||
<FeaturedCreators featuredCreators={creators} title="Creators" />
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user