add sorting of creators too

This commit is contained in:
SwiftyOS
2024-11-29 16:16:47 +01:00
parent a971d59974
commit a4b186cf81
4 changed files with 21 additions and 2 deletions

View File

@@ -192,6 +192,8 @@ async def get_store_creators(
description=creator.description,
avatar_url=creator.avatar_url,
num_agents=creator.num_agents,
agent_rating=creator.agent_rating,
agent_runs=creator.agent_runs,
)
for creator in creators
]

View File

@@ -71,6 +71,8 @@ class Creator(pydantic.BaseModel):
description: str
avatar_url: str
num_agents: int
agent_rating: float
agent_runs: int
class CreatorsResponse(pydantic.BaseModel):

View File

@@ -83,13 +83,13 @@ function SearchResults({
};
const handleSortChange = (sortValue: string) => {
let sortBy = "recent";
if (sortValue === "runs") {
sortBy = "runs";
} else if (sortValue === "rating") {
sortBy = "rating";
sortBy = "rating";
}
const sortedAgents = [...agents].sort((a, b) => {
if (sortBy === "runs") {
return b.runs - a.runs;
@@ -99,7 +99,20 @@ function SearchResults({
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);
};
return (

View File

@@ -393,6 +393,8 @@ export type Creator = {
description: string;
avatar_url: string;
num_agents: number;
agent_rating: number;
agent_runs: number;
};
export type CreatorsResponse = {