From 7dcf89c47ee31d10fc1eae7cde3a921efeb2c0c1 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 15 Aug 2025 17:22:01 -0400 Subject: [PATCH] Add conditional sorting logic for Month span in memories sorting --- src/memories.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/memories.rs b/src/memories.rs index fb0248d..2468b41 100644 --- a/src/memories.rs +++ b/src/memories.rs @@ -285,21 +285,27 @@ pub async fn list_memories( } } - // Sort by day of the month and time (using the created timestamp) - memories_with_dates.sort_by(|a, b| { - let day_comparison = a.1.day().cmp(&b.1.day()); + match span_mode { + // Sort by absolute time for a more 'overview' + MemoriesSpan::Month => memories_with_dates.sort_by(|a, b| a.1.cmp(&b.1)), + _ => { + memories_with_dates.sort_by(|a, b| { + let day_comparison = a.1.day().cmp(&b.1.day()); - if day_comparison == std::cmp::Ordering::Equal { - match (a.0.created, b.0.created) { - (Some(a_time), Some(b_time)) => a_time.cmp(&b_time), - (Some(_), None) => std::cmp::Ordering::Less, - (None, Some(_)) => std::cmp::Ordering::Greater, - (None, None) => std::cmp::Ordering::Equal, - } - } else { - day_comparison + if day_comparison == std::cmp::Ordering::Equal { + match (a.0.created, b.0.created) { + (Some(a_time), Some(b_time)) => a_time.cmp(&b_time), + (Some(_), None) => std::cmp::Ordering::Less, + (None, Some(_)) => std::cmp::Ordering::Greater, + (None, None) => std::cmp::Ordering::Equal, + } + } else { + day_comparison + } + }); } - }); + } + // Sort by day of the month and time (using the created timestamp) let items: Vec = memories_with_dates.into_iter().map(|(m, _)| m).collect();