Files
YouTube-Manager/Manager.App/Components/Application/Dev/DevelopmentVideo.razor.cs

56 lines
1.8 KiB
C#

using Manager.App.Models.System;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using MudBlazor;
namespace Manager.App.Components.Application.Dev;
public partial class DevelopmentVideo : ComponentBase
{
private YouTubeClientItem? _selectedClient;
private string _videoId = "";
private async Task<IEnumerable<YouTubeClientItem>> SearchClientsAsync(string? search, CancellationToken cancellationToken)
{
var searchResults = await ClientService.GetClientsAsync(search, cancellationToken: cancellationToken);
return !searchResults.IsSuccess ? [] : searchResults.Value;
}
private async Task GetDataAsync(MouseEventArgs obj)
{
if (_selectedClient == null)
{
Snackbar.Add("No client selected!", Severity.Warning);
return;
}
if (string.IsNullOrWhiteSpace(_videoId))
{
Snackbar.Add("No video ID set!", Severity.Warning);
return;
}
if (_videoId.Length != 11)
{
Snackbar.Add("Video ID needs to have an length of 11 chars!", Severity.Warning);
}
var clientResult = await ClientService.LoadClientByIdAsync(_selectedClient.Id);
if (!clientResult.IsSuccess)
{
Snackbar.Add(clientResult.Error?.Description ?? $"Failed to get client with id: {_selectedClient.Id}", Severity.Error);
return;
}
var ytClient = clientResult.Value;
var videoResult = await ytClient.GetVideoByIdAsync(_videoId);
if (!videoResult.IsSuccess)
{
Snackbar.Add(videoResult.Error?.Description ?? $"Failed to load video: {_videoId}", Severity.Error);
return;
}
var ytVideo = videoResult.Value;
Snackbar.Add($"Loaded video {ytVideo.Title}", Severity.Success);
}
}