Fix the sorting when adding mails.

This commit is contained in:
Burak Kaan Köse
2025-11-01 12:35:47 +01:00
parent b60832a270
commit ae9e35e091
6 changed files with 37 additions and 4 deletions
@@ -42,10 +42,21 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
public ReadOnlyObservableGroupedCollection<object, IMailListItem> MailItems { get; }
private SortingOptionType _sortingType;
/// <summary>
/// Property that defines how the item sorting should be done in the collection.
/// </summary>
public SortingOptionType SortingType { get; set; }
public SortingOptionType SortingType
{
get => _sortingType;
set
{
_sortingType = value;
// Update the comparer's sort mode when sorting type changes
listComparer.SortByName = value == SortingOptionType.Sender;
}
}
/// <summary>
/// Gets or sets the grouping type for emails.
@@ -79,6 +90,9 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
{
MailItems = new ReadOnlyObservableGroupedCollection<object, IMailListItem>(_mailItemSource);
// Initialize sorting type to default (date-based)
SortingType = SortingOptionType.ReceiveDate;
Messenger.Register<SelectedItemsChangedMessage>(this);
}
+1 -1
View File
@@ -9,7 +9,7 @@ namespace Wino.Mail.ViewModels.Data;
/// Common interface for mail items that can be displayed in a mail list.
/// Implemented by both MailItemViewModel and ThreadMailItemViewModel.
/// </summary>
public interface IMailListItem : IMailHashContainer, INotifyPropertyChanged
public interface IMailListItem : IMailHashContainer, IMailListItemSorting, INotifyPropertyChanged
{
/// <summary>
/// Gets the latest creation date for sorting purposes.
@@ -171,6 +171,10 @@ public partial class MailItemViewModel(MailCopy mailCopy) : ObservableRecipient,
set => SetProperty(MailCopy.SenderContact.Base64ContactPicture, value, MailCopy, (u, n) => u.SenderContact.Base64ContactPicture = n);
}
public DateTime SortingDate => CreationDate;
public string SortingName => FromName;
public IEnumerable<Guid> GetContainingIds() => [MailCopy.UniqueId];
public IEnumerable<MailItemViewModel> GetSelectedMailItems()
@@ -167,6 +167,10 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IMailListIte
private MailItemViewModel latestMailViewModel => ThreadEmails.OrderByDescending(e => e.MailCopy?.CreationDate).FirstOrDefault()!;
public DateTime SortingDate => CreationDate;
public string SortingName => FromName;
public ThreadMailItemViewModel(string threadId)
{
_threadId = threadId;