78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
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<ProspectSortOption> 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<ProspectSortOption?>(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();
|
|
}
|
|
} |