Add conditional sorting logic for Month span in memories sorting
This commit is contained in:
@@ -285,21 +285,27 @@ pub async fn list_memories(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by day of the month and time (using the created timestamp)
|
match span_mode {
|
||||||
memories_with_dates.sort_by(|a, b| {
|
// Sort by absolute time for a more 'overview'
|
||||||
let day_comparison = a.1.day().cmp(&b.1.day());
|
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 {
|
if day_comparison == std::cmp::Ordering::Equal {
|
||||||
match (a.0.created, b.0.created) {
|
match (a.0.created, b.0.created) {
|
||||||
(Some(a_time), Some(b_time)) => a_time.cmp(&b_time),
|
(Some(a_time), Some(b_time)) => a_time.cmp(&b_time),
|
||||||
(Some(_), None) => std::cmp::Ordering::Less,
|
(Some(_), None) => std::cmp::Ordering::Less,
|
||||||
(None, Some(_)) => std::cmp::Ordering::Greater,
|
(None, Some(_)) => std::cmp::Ordering::Greater,
|
||||||
(None, None) => std::cmp::Ordering::Equal,
|
(None, None) => std::cmp::Ordering::Equal,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
day_comparison
|
day_comparison
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
// Sort by day of the month and time (using the created timestamp)
|
||||||
|
|
||||||
let items: Vec<MemoryItem> = memories_with_dates.into_iter().map(|(m, _)| m).collect();
|
let items: Vec<MemoryItem> = memories_with_dates.into_iter().map(|(m, _)| m).collect();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user