[CHANGE] Add account dialog
This commit is contained in:
@@ -1,61 +1,18 @@
|
||||
@page "/Channels"
|
||||
@using Manager.App.Models.Settings
|
||||
@using Microsoft.Extensions.Options
|
||||
|
||||
@inject ILibraryService LibraryService
|
||||
@inject IDialogService DialogService
|
||||
@inject IOptions<LibrarySettings> LibraryOptions
|
||||
|
||||
<PageTitle>Channels</PageTitle>
|
||||
|
||||
|
||||
<MudDialog @bind-Visible="@_addAccountDialogVisible" Options="_dialogOptions">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Add new account</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudDataGrid Items="_cookies" Dense Elevation="0" Outlined>
|
||||
<Header>
|
||||
<MudStack Class="ma-2">
|
||||
<MudText>Cookies</MudText>
|
||||
</MudStack>
|
||||
<MudStack Row Spacing="2" Class="ma-1">
|
||||
<MudTooltip Text="Add cookie">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Add" Size="Size.Small" Color="Color.Success" OnClick="() => _cookies.Add(new HttpCookie())"/>
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Add from text">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.InsertDriveFile" Size="Size.Small" Color="Color.Primary" Disabled/>
|
||||
</MudTooltip>
|
||||
</MudStack>
|
||||
</Header>
|
||||
<Columns>
|
||||
<TemplateColumn Title="Name">
|
||||
<CellTemplate>
|
||||
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Name" Immediate/>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="Value">
|
||||
<CellTemplate>
|
||||
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Value" Immediate/>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
|
||||
<TemplateColumn>
|
||||
<CellTemplate>
|
||||
<MudTooltip Text="Remove">
|
||||
<MudIconButton Size="Size.Small" Icon="@Icons.Material.Filled.Remove" Color="Color.Error" OnClick="() => _cookies.Remove(context.Item)"/>
|
||||
</MudTooltip>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudStack Spacing="2" Row>
|
||||
<MudButton Color="Color.Error" OnClick="() => _addAccountDialogVisible = false" Variant="Variant.Outlined">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" Variant="Variant.Outlined" Disabled>Save</MudButton>
|
||||
</MudStack>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<MudStack Spacing="2">
|
||||
<MudPaper Elevation="0" Outlined>
|
||||
<MudStack Row Class="ma-2">
|
||||
<MudButton IconSize="Size.Small" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Outlined" OnClick="() => _addAccountDialogVisible = true">Add account</MudButton>
|
||||
<MudButton IconSize="Size.Small" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Outlined" OnClick="OnAddAccountDialogAsync">Add account</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using Manager.App.Components.Dialogs;
|
||||
using Manager.Data.Entities.LibraryContext;
|
||||
using Manager.YouTube;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
@@ -6,23 +8,26 @@ namespace Manager.App.Components.Pages;
|
||||
|
||||
public partial class Channels : ComponentBase
|
||||
{
|
||||
private bool _addAccountDialogVisible;
|
||||
private DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true };
|
||||
private List<HttpCookie> _cookies = [];
|
||||
private readonly DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true, MaxWidth = MaxWidth.ExtraLarge };
|
||||
|
||||
private async Task<TableData<ChannelEntity>> ServerReload(TableState state, CancellationToken token)
|
||||
{
|
||||
var results = await LibraryService.GetChannelAccountsAsync(state.Page * state.PageSize, state.PageSize, token);
|
||||
if (!results.IsSuccess)
|
||||
{
|
||||
return new TableData<ChannelEntity>();
|
||||
}
|
||||
|
||||
return new TableData<ChannelEntity> { Items = results.Value, TotalItems = results.Total };
|
||||
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;
|
||||
|
||||
public record HttpCookie()
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
if (result == null || result.Canceled || result.Data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var client = (YouTubeClient)result.Data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user