From 960e2ee5274620f2b5bc5f63687184ac9f32ad1a Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Mon, 24 Nov 2025 21:18:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Enhance=20favorites=20manag?= =?UTF-8?q?ement=20with=20validation,=20update=20data=20structure,=20and?= =?UTF-8?q?=20improve=20UI=20interactions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/server/controllers/FavoritesController.js | 22 ++++++ client/src/components/Agents/AgentCard.tsx | 6 ++ .../Conversations/Conversations.tsx | 2 +- .../components/Nav/Favorites/FavoriteItem.tsx | 2 +- .../Nav/Favorites/FavoritesList.tsx | 69 +++++++++++++++++-- client/src/components/Nav/Nav.tsx | 6 +- client/src/hooks/useFavorites.ts | 17 +++-- client/src/locales/en/translation.json | 2 +- packages/data-provider/src/data-service.ts | 10 ++- packages/data-schemas/src/types/user.ts | 12 ++-- 10 files changed, 117 insertions(+), 31 deletions(-) diff --git a/api/server/controllers/FavoritesController.js b/api/server/controllers/FavoritesController.js index bca08035c..cc34cb1e5 100644 --- a/api/server/controllers/FavoritesController.js +++ b/api/server/controllers/FavoritesController.js @@ -9,6 +9,28 @@ const updateFavoritesController = async (req, res) => { return res.status(400).json({ message: 'Favorites data is required' }); } + // Validate favorites structure + if (!Array.isArray(favorites)) { + return res.status(400).json({ message: 'Favorites must be an array' }); + } + + for (const fav of favorites) { + const hasAgent = !!fav.agentId; + const hasModel = !!(fav.model && fav.endpoint); + + if (!hasAgent && !hasModel) { + return res.status(400).json({ + message: 'Each favorite must have either agentId or model+endpoint', + }); + } + + if (hasAgent && hasModel) { + return res.status(400).json({ + message: 'Favorite cannot have both agentId and model/endpoint', + }); + } + } + const user = await User.findByIdAndUpdate( userId, { $set: { favorites } }, diff --git a/client/src/components/Agents/AgentCard.tsx b/client/src/components/Agents/AgentCard.tsx index 751cab9b6..6a81a1645 100644 --- a/client/src/components/Agents/AgentCard.tsx +++ b/client/src/components/Agents/AgentCard.tsx @@ -48,6 +48,12 @@ const AgentCard: React.FC = ({ agent, onClick, className = '' }) aria-describedby={`agent-${agent.id}-description`} tabIndex={0} role="button" + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + onClick(); + } + }} >
diff --git a/client/src/components/Conversations/Conversations.tsx b/client/src/components/Conversations/Conversations.tsx index 57dd8fcd4..4af011947 100644 --- a/client/src/components/Conversations/Conversations.tsx +++ b/client/src/components/Conversations/Conversations.tsx @@ -175,7 +175,7 @@ const Conversations: FC = ({ } let rendering: JSX.Element; if (item.type === 'favorites') { - rendering = ; + rendering = ; } else if (item.type === 'chats-header') { rendering = (