Improve Memory sorting
This commit is contained in:
@@ -237,11 +237,14 @@ pub async fn list_memories(
|
||||
};
|
||||
|
||||
let now = if let Some(tz) = client_timezone {
|
||||
debug!("Client timezone: {:?}", tz);
|
||||
Utc::now().with_timezone(&tz).date_naive()
|
||||
} else {
|
||||
Local::now().date_naive()
|
||||
};
|
||||
|
||||
debug!("Now: {:?}", now);
|
||||
|
||||
let base = Path::new(&app_state.base_path);
|
||||
|
||||
let mut memories_with_dates: Vec<(MemoryItem, NaiveDate)> = Vec::new();
|
||||
@@ -282,8 +285,21 @@ pub async fn list_memories(
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by day of the month
|
||||
memories_with_dates.sort_by_key(|k| k.1.day());
|
||||
// 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());
|
||||
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
let items: Vec<MemoryItem> = memories_with_dates.into_iter().map(|(m, _)| m).collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user