From 3c3b6b853abf4aa60125ac9c5d29a17c16e9b8e0 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Wed, 8 Jul 2026 09:25:41 -0400 Subject: [PATCH] Fix cook history ordering: sort months by date, not name groupEntries was sorting month groups by reverse-alphabetical name (e.g. 'June' before 'July'), producing oldest-first ordering. Now sorts by the actual entry dates within each group (newest first). Combined with the earlier DESC fix in fetchAllEntries, the cook history page now shows newest months at top, newest entries within each month at top. --- src/Roux/Server.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Roux/Server.hs b/src/Roux/Server.hs index 6aa07e2..5e9bf8e 100644 --- a/src/Roux/Server.hs +++ b/src/Roux/Server.hs @@ -759,13 +759,16 @@ parseDate t = case T.splitOn "-" t of fromGregorianValid y' m' d' _ -> Nothing --- | Group entries by month label (e.g. "March 2026"). +-- | Group entries by month label (e.g. "March 2026"), sorted newest-first. groupEntries :: [CookLog.CookEntry] -> [(Text, [CookLog.CookEntry])] groupEntries [] = [] groupEntries entries = let monthKey d = T.pack $ Time.formatTime Time.defaultTimeLocale "%B %Y" d groups = Map.fromListWith (++) [(monthKey (CookLog.ceCookedDate e), [e]) | e <- entries] - sortedMonths = reverse (Map.keys groups) + -- Sort month groups by the newest entry date in each group, descending. + -- Every group is non-empty by construction. + monthDate = foldl max (toEnum 0) . map CookLog.ceCookedDate + sortedMonths = map fst $ sortOn (Down . monthDate . snd) $ Map.toList groups in [(m, Map.findWithDefault [] m groups) | m <- sortedMonths] -- | Look up a recipe by filename (case-insensitive, .cook extension optional).