From a38c1d2aad2ab8a41876040030f3a779781f2741 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Tue, 17 Feb 2026 04:03:56 +0100 Subject: [PATCH] updated dashboard sorting --- frontend/src/pages/Dashboard.tsx | 84 ++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index c804a1a..96a867b 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -60,16 +60,23 @@ const Dashboard: React.FC = () => { if (loading) return ; if (!data) return Please login to view dashboard.; - const groupBy = (array: any[]) => { - return array.reduce((result, currentValue) => { + const groupAndSort = (array: any[], sortKey: string) => { + const grouped = array.reduce((result, currentValue) => { const groupKey = currentValue.category_name || currentValue.flavor?.category_name || 'Other'; (result[groupKey] = result[groupKey] || []).push(currentValue); return result; }, {}); + + // Sort items within each group + Object.keys(grouped).forEach(key => { + grouped[key].sort((a: any, b: any) => (b[sortKey] || 0) - (a[sortKey] || 0)); + }); + + return grouped; }; - const ratedGrouped = groupBy(data.my_ratings); - const missingGrouped = groupBy(data.missing_flavors); + const ratedGrouped = groupAndSort(data.my_ratings, 'score'); + const missingGrouped = groupAndSort(data.missing_flavors, 'average_rating'); return ( @@ -209,33 +216,48 @@ const Dashboard: React.FC = () => { gap: 2 }}> {flavors.map((flavor: any) => ( - - - - - - - - {flavor.name} - - - - + + + + + + + {(flavor.average_rating || 0).toFixed(1)}/10 + + + + + {flavor.name} + + + + + ))}