@page "/media/multi-collections" @using ErsatzTV.Application.Configuration @using ErsatzTV.Application.MediaCollections @implements IDisposable @inject IDialogService Dialog @inject IMediator Mediator
Add Multi Collection
Multi Collections @context.Name
@code { private CancellationTokenSource _cts; private MudTable _multiCollectionsTable; private int _multiCollectionsRowsPerPage = 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 { _multiCollectionsRowsPerPage = await Mediator.Send(new GetConfigElementByKey(ConfigElementKey.MultiCollectionsPageSize), token) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); } catch (OperationCanceledException) { // do nothing } } private async Task DeleteMultiCollection(MultiCollectionViewModel collection) { var parameters = new DialogParameters { { "EntityType", "multi collection" }, { "EntityName", collection.Name } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = await Dialog.ShowAsync("Delete Multi Collection", parameters, options); DialogResult result = await dialog.Result; if (result is { Canceled: false }) { await Mediator.Send(new DeleteMultiCollection(collection.Id), _cts.Token); if (_multiCollectionsTable != null) { await _multiCollectionsTable.ReloadServerData(); } } } private async Task> ServerReloadMultiCollections(TableState state, CancellationToken cancellationToken) { await Mediator.Send(new SaveConfigElementByKey(ConfigElementKey.MultiCollectionsPageSize, state.PageSize.ToString()), cancellationToken); PagedMultiCollectionsViewModel data = await Mediator.Send(new GetPagedMultiCollections(_searchString, state.Page, state.PageSize), cancellationToken); return new TableData { TotalItems = data.TotalCount, Items = data.Page }; } private void OnSearch(string query) { _searchString = query; _multiCollectionsTable.ReloadServerData(); } }