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}
+
+
+
+
+
))}