diff --git a/FoodsharingSiegen.Contracts/StorageKeys.cs b/FoodsharingSiegen.Contracts/StorageKeys.cs
index c3334ad..27a901a 100644
--- a/FoodsharingSiegen.Contracts/StorageKeys.cs
+++ b/FoodsharingSiegen.Contracts/StorageKeys.cs
@@ -12,6 +12,26 @@ namespace FoodsharingSiegen.Contracts
///
public const string ProspectFilter = "ProspectFilter";
+ ///
+ /// Represents the storage key used for prospect sorting preferences.
+ ///
+ public const string SortProspects = "SortProspects";
+
+ ///
+ /// Represents the storage key used for sorting all prospects.
+ ///
+ public const string SortProspectsAll = "SortProspectsAll";
+
+ ///
+ /// Represents the storage key used for sorting completed prospects.
+ ///
+ public const string SortProspectsDone = "SortProspectsDone";
+
+ ///
+ /// Represents the storage key used for sorting prospects pending verification.
+ ///
+ public const string SortProspectsVerify = "SortProspectsVerify";
+
///
/// The token key
///
diff --git a/FoodsharingSiegen.Server/Controls/ProspectSortControl.razor b/FoodsharingSiegen.Server/Controls/ProspectSortControl.razor
new file mode 100644
index 0000000..398e8c8
--- /dev/null
+++ b/FoodsharingSiegen.Server/Controls/ProspectSortControl.razor
@@ -0,0 +1,17 @@
+@using FoodsharingSiegen.Contracts.Enums
+
+
+
+
+ @if (HasCustomSort)
+ {
+ @CurrentSortText
+ }
+
\ No newline at end of file
diff --git a/FoodsharingSiegen.Server/Controls/ProspectSortControl.razor.cs b/FoodsharingSiegen.Server/Controls/ProspectSortControl.razor.cs
new file mode 100644
index 0000000..ec79afa
--- /dev/null
+++ b/FoodsharingSiegen.Server/Controls/ProspectSortControl.razor.cs
@@ -0,0 +1,78 @@
+using Blazorise;
+using FoodsharingSiegen.Contracts.Entity;
+using FoodsharingSiegen.Contracts.Enums;
+using FoodsharingSiegen.Server.Data.Service;
+using FoodsharingSiegen.Server.Dialogs;
+using FoodsharingSiegen.Server.Service;
+using Microsoft.AspNetCore.Components;
+
+namespace FoodsharingSiegen.Server.Controls;
+
+public partial class ProspectSortControl
+{
+ [Inject] private IModalService ModalService { get; set; } = null!;
+
+ [Inject] private LocalStorageService LocalStorageService { get; set; } = null!;
+
+ [Parameter]
+ public ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
+
+ [Parameter]
+ public EventCallback CurrentSortChanged { get; set; }
+
+ [Parameter]
+ public EventCallback OnSortChanged { get; set; }
+
+ [Parameter]
+ public string? StorageKey { get; set; }
+
+ protected override async Task OnInitializedAsync()
+ {
+ if (!string.IsNullOrEmpty(StorageKey))
+ {
+ var savedSort = await LocalStorageService.GetItem(StorageKey);
+ if (savedSort.HasValue)
+ {
+ CurrentSort = savedSort.Value;
+ await CurrentSortChanged.InvokeAsync(CurrentSort);
+ }
+ }
+ await base.OnInitializedAsync();
+ }
+
+ private async Task OpenSortDialogAsync()
+ {
+ await ProspectSortDialog.ShowAsync(ModalService, CurrentSort, async option =>
+ {
+ await UpdateSortAsync(option);
+ });
+ }
+
+ private bool HasCustomSort => CurrentSort != ProspectSortOption.NameAscending;
+
+ private string CurrentSortText => CurrentSort switch
+ {
+ ProspectSortOption.NameDescending => "Sortierung: Name (absteigend)",
+ ProspectSortOption.ModifiedAscending => "Sortierung: Zuletzt geändert (aufsteigend)",
+ ProspectSortOption.ModifiedDescending => "Sortierung: Zuletzt geaendert (absteigend)",
+ _ => string.Empty
+ };
+
+ private async Task ResetSortAsync()
+ {
+ await UpdateSortAsync(ProspectSortOption.NameAscending);
+ }
+
+ private async Task UpdateSortAsync(ProspectSortOption option)
+ {
+ CurrentSort = option;
+
+ if (!string.IsNullOrEmpty(StorageKey))
+ {
+ await LocalStorageService.SetItem(StorageKey, CurrentSort);
+ }
+
+ await CurrentSortChanged.InvokeAsync(CurrentSort);
+ await OnSortChanged.InvokeAsync();
+ }
+}
\ No newline at end of file
diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor b/FoodsharingSiegen.Server/Pages/Prospects.razor
index 797c6cb..d4a1ad3 100644
--- a/FoodsharingSiegen.Server/Pages/Prospects.razor
+++ b/FoodsharingSiegen.Server/Pages/Prospects.razor
@@ -2,6 +2,7 @@
@page "/prospect"
@page "/prospects"
+@using FoodsharingSiegen.Contracts
@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Shared.Helper
@inherits FsBase
@@ -25,28 +26,11 @@
>
-
-
-
- @if (HasCustomSort)
- {
- @CurrentSortText
- }
-
-
-
+
@{
var filterList = ProspectList.ApplyFilter(Filter);
- var sortList = SortProspects(filterList);
+ var sortList = filterList.ApplySort(CurrentSort);
}
diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs
index fa3c3e8..5e12399 100644
--- a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs
+++ b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs
@@ -65,32 +65,6 @@ namespace FoodsharingSiegen.Server.Pages
await EditProspectDialog.ShowAsync(ModalService, LoadProspects);
}
- private async Task OpenSortDialogAsync()
- {
- await ProspectSortDialog.ShowAsync(ModalService, CurrentSort, async option =>
- {
- CurrentSort = option;
-
- await InvokeAsync(StateHasChanged);
- });
- }
-
- private bool HasCustomSort => CurrentSort != ProspectSortOption.NameAscending;
-
- private string CurrentSortText => CurrentSort switch
- {
- ProspectSortOption.NameDescending => "Sortierung: Name (absteigend)",
- ProspectSortOption.ModifiedAscending => "Sortierung: Zuletzt geaendert (aufsteigend) ",
- ProspectSortOption.ModifiedDescending => "Sortierung: Zuletzt geaendert (absteigend) ",
- _ => string.Empty
- };
-
- private async Task ResetSortAsync()
- {
- CurrentSort = ProspectSortOption.NameAscending;
- await InvokeAsync(StateHasChanged);
- }
-
#endregion
#region Private Method FilterChangedAsync
@@ -106,18 +80,6 @@ namespace FoodsharingSiegen.Server.Pages
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
}
- private List SortProspects(List prospects)
- {
- return CurrentSort switch
- {
- ProspectSortOption.NameAscending => prospects.OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(),
- ProspectSortOption.NameDescending => prospects.OrderByDescending(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(),
- ProspectSortOption.ModifiedAscending => prospects.OrderBy(x => x.Modified ?? x.Created).ToList(),
- ProspectSortOption.ModifiedDescending => prospects.OrderByDescending(x => x.Modified ?? x.Created).ToList(),
- _ => prospects
- };
- }
-
#endregion
#region Private Method LoadProspects
diff --git a/FoodsharingSiegen.Server/Pages/ProspectsAll.razor b/FoodsharingSiegen.Server/Pages/ProspectsAll.razor
index 5617172..e7e4d36 100644
--- a/FoodsharingSiegen.Server/Pages/ProspectsAll.razor
+++ b/FoodsharingSiegen.Server/Pages/ProspectsAll.razor
@@ -1,6 +1,7 @@
@page "/all"
@page "/archive"
+@using FoodsharingSiegen.Contracts
@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Shared.Helper
@inherits FsBase
@@ -13,15 +14,18 @@
TESTMODUS! Änderungen werden wieder gelöscht.
}
+
+
@{
var filterList = ProspectList.ApplyFilter(Filter);
+ var sortList = filterList.ApplySort(CurrentSort);
}
\ No newline at end of file
diff --git a/FoodsharingSiegen.Server/Pages/ProspectsAll.razor.cs b/FoodsharingSiegen.Server/Pages/ProspectsAll.razor.cs
index 60b59ac..e23cfcc 100644
--- a/FoodsharingSiegen.Server/Pages/ProspectsAll.razor.cs
+++ b/FoodsharingSiegen.Server/Pages/ProspectsAll.razor.cs
@@ -39,6 +39,8 @@ namespace FoodsharingSiegen.Server.Pages
///
private List? ProspectList { get; set; }
+ private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
+
#endregion
#region Override InitializeDataAsync
diff --git a/FoodsharingSiegen.Server/Pages/ProspectsDone.razor b/FoodsharingSiegen.Server/Pages/ProspectsDone.razor
index e52c6db..762a9b8 100644
--- a/FoodsharingSiegen.Server/Pages/ProspectsDone.razor
+++ b/FoodsharingSiegen.Server/Pages/ProspectsDone.razor
@@ -1,5 +1,6 @@
@page "/done"
+@using FoodsharingSiegen.Contracts
@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Shared.Helper
@inherits FsBase
@@ -12,15 +13,18 @@
TESTMODUS! Änderungen werden wieder gelöscht.
}
+
+
@{
var filterList = ProspectList.ApplyFilter(Filter);
+ var sortList = filterList.ApplySort(CurrentSort);
}
\ No newline at end of file
diff --git a/FoodsharingSiegen.Server/Pages/ProspectsDone.razor.cs b/FoodsharingSiegen.Server/Pages/ProspectsDone.razor.cs
index 65655e4..18677d3 100644
--- a/FoodsharingSiegen.Server/Pages/ProspectsDone.razor.cs
+++ b/FoodsharingSiegen.Server/Pages/ProspectsDone.razor.cs
@@ -31,6 +31,8 @@ namespace FoodsharingSiegen.Server.Pages
///
private List? ProspectList { get; set; }
+ private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
+
#endregion
#region Override InitializeDataAsync
diff --git a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor
index 2c6e686..b03b6f2 100644
--- a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor
+++ b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor
@@ -1,5 +1,6 @@
@page "/verify"
+@using FoodsharingSiegen.Contracts
@using FoodsharingSiegen.Contracts.Enums
@using FoodsharingSiegen.Shared.Helper
@inherits FsBase
@@ -12,15 +13,18 @@
TESTMODUS! Änderungen werden wieder gelöscht.
}
+
+
@{
var filterList = ProspectList.ApplyFilter(Filter);
+ var sortList = filterList.ApplySort(CurrentSort);
}
\ No newline at end of file
diff --git a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs
index 3501bac..502bdf4 100644
--- a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs
+++ b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs
@@ -37,6 +37,8 @@ namespace FoodsharingSiegen.Server.Pages
///
private List? ProspectList { get; set; }
+ private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
+
#endregion
#region Override InitializeDataAsync
diff --git a/FoodsharingSiegen.Shared/Helper/FilterHelper.cs b/FoodsharingSiegen.Shared/Helper/FilterHelper.cs
index 838ffc0..6f8317d 100644
--- a/FoodsharingSiegen.Shared/Helper/FilterHelper.cs
+++ b/FoodsharingSiegen.Shared/Helper/FilterHelper.cs
@@ -56,6 +56,20 @@ namespace FoodsharingSiegen.Shared.Helper
return filterListQ.ToList();
}
+ public static List ApplySort(this List? prospectList, ProspectSortOption sortOption)
+ {
+ if (prospectList == null) return [];
+
+ return sortOption switch
+ {
+ ProspectSortOption.NameAscending => prospectList.OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(),
+ ProspectSortOption.NameDescending => prospectList.OrderByDescending(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(),
+ ProspectSortOption.ModifiedAscending => prospectList.OrderBy(x => x.Modified ?? x.Created).ToList(),
+ ProspectSortOption.ModifiedDescending => prospectList.OrderByDescending(x => x.Modified ?? x.Created).ToList(),
+ _ => prospectList
+ };
+ }
+
#endregion
}
}
\ No newline at end of file