Fix cook history ordering: sort months by date, not name
Build and Deploy / build-and-deploy (push) Successful in 1m46s
Build and Deploy / build-and-deploy (push) Successful in 1m46s
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.
This commit is contained in:
+5
-2
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user