@page "/media/smart-collections" @using ErsatzTV.Application.Configuration @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Extensions @implements IDisposable @inject IDialogService Dialog @inject IMediator Mediator
Smart Collections @context.Name
@code { private CancellationTokenSource _cts; private MudTable _smartCollectionsTable; private int _smartCollectionsRowsPerPage = 10; private string _searchString; public void Dispose() { _cts?.Cancel(); _cts?.Dispose(); } protected override async Task OnParametersSetAsync() { _cts?.Cancel(); _cts?.Dispose(); _cts = new CancellationTokenSource(); var token = _cts.Token; try { _smartCollectionsRowsPerPage = await Mediator.Send(new GetConfigElementByKey(ConfigElementKey.SmartCollectionsPageSize), token) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); } catch (OperationCanceledException) { // do nothing } } private async Task DeleteSmartCollection(SmartCollectionViewModel collection) { var parameters = new DialogParameters { { "EntityType", "smart collection" }, { "EntityName", collection.Name } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = await Dialog.ShowAsync("Delete Smart Collection", parameters, options); DialogResult result = await dialog.Result; if (result is { Canceled: false }) { await Mediator.Send(new DeleteSmartCollection(collection.Id), _cts.Token); if (_smartCollectionsTable != null) { await _smartCollectionsTable.ReloadServerData(); } } } private async Task> ServerReloadSmartCollections(TableState state, CancellationToken cancellationToken) { await Mediator.Send(new SaveConfigElementByKey(ConfigElementKey.SmartCollectionsPageSize, state.PageSize.ToString()), cancellationToken); PagedSmartCollectionsViewModel data = await Mediator.Send(new GetPagedSmartCollections(_searchString, state.Page, state.PageSize), cancellationToken); return new TableData { TotalItems = data.TotalCount, Items = data.Page }; } private void OnSearch(string query) { _searchString = query; _smartCollectionsTable.ReloadServerData(); } }