Files
YouTube-Manager/Manager.App/Components/Pages/Channels.razor.cs

67 lines
2.6 KiB
C#

using Manager.App.Components.Dialogs;
using Manager.App.Models.Library;
using Manager.Data.Entities.LibraryContext;
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace Manager.App.Components.Pages;
public partial class Channels : ComponentBase
{
private readonly DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true, MaxWidth = MaxWidth.ExtraLarge };
private MudTable<ChannelEntity>? _table;
private async Task<TableData<ChannelEntity>> ServerReload(TableState state, CancellationToken token)
{
var results = await LibraryService.GetChannelsAsync(state.PageSize, state.Page * state.PageSize, token);
return !results.IsSuccess ? new TableData<ChannelEntity>() : new TableData<ChannelEntity> { Items = results.Value, TotalItems = results.Total };
}
private async Task OnAddAccountDialogAsync()
{
var libSettings = LibraryOptions.Value;
var parameters = new DialogParameters<AccountDialog> { { x => x.DefaultUserAgent, libSettings.DefaultUserAgent } };
var dialog = await DialogService.ShowAsync<AccountDialog>("Add account", parameters, _dialogOptions);
var result = await dialog.Result;
if (result == null || result.Canceled || result.Data == null)
{
return;
}
var clientChannel = (ClientChannel)result.Data;
if (clientChannel?.YouTubeClient == null)
{
Snackbar.Add("No YouTube client received.", Severity.Error);
return;
}
var savedClientResult = await ClientService.SaveClientAsync(clientChannel.YouTubeClient);
if (savedClientResult.IsSuccess)
{
if (_table != null)
{
await _table.ReloadServerData();
}
Snackbar.Add($"Client {clientChannel.Channel?.Handle ?? clientChannel.YouTubeClient.Id} saved!", Severity.Success);
ClientService.AddClient(clientChannel.YouTubeClient);
}
else
{
Snackbar.Add($"Failed to store client: {savedClientResult.Error?.Description ?? "Unknown!"}", Severity.Error);
}
if (clientChannel.Channel == null)
{
Snackbar.Add("No channel information received!", Severity.Warning);
}
else
{
var saveChannelResult = await LibraryService.SaveChannelAsync(clientChannel.Channel);
if (!saveChannelResult.IsSuccess)
{
Snackbar.Add("Failed to save channel information", Severity.Warning);
}
}
}
}