poster adding and deleting actions added

This commit is contained in:
2024-09-16 23:59:51 +02:00
Unverified
parent cc22e609e1
commit a0f565d03d
8 changed files with 116 additions and 9 deletions

View File

@@ -66,7 +66,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
{ {
string url = GetUrl(EndpointsConfiguration.Media.PutPoster, mediaId); string url = GetUrl(EndpointsConfiguration.Media.PutPoster, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url) HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
{ {
Body = data Body = data
}; };

View File

@@ -1,11 +1,24 @@
<div class="row"> <div class="row">
<div class="col-auto rounded-3 panel panel-regular m-1"> <div class="col-auto rounded-3 panel panel-regular m-1 p-3">
<img class="rounded-2 m-2 mt-3 shadow" src="@(_posterBase64 is not null ? $"data:{_posterMediaType};base64,{_posterBase64}" : "assets/poster.png")" alt="poster" width="300" height="500"/> <img class="rounded-2 shadow mb-1" src="@(_posterBase64 is not null ? $"data:{_posterMediaType};base64,{_posterBase64}" : "assets/poster.png")" alt="poster" width="300" height="500"/>
<br/> <br/>
<InputFile id="posterInput" class="m-2 form-control" OnChange="LoadPoster" disabled=@(!Id.HasValue) autocomplete="off"/> <InputFile id="posterInput" class="form-control my-1" OnChange="LoadPoster" disabled=@(!Id.HasValue) autocomplete="off"/>
@if (_posterChanged) @if (_posterChanged)
{ {
<button id="posterButton" type="button" class="btn btn-secondary m-2 mb-3 form-control" @onclick="SavePoster" disabled=@(!Id.HasValue) autocomplete="off">Save poster</button> <div id="posterButtons" class="container-fluid mt-2">
<div class="row">
<button type="button" class="col btn btn-secondary me-1" @onclick="SavePoster" disabled=@(!Id.HasValue) autocomplete="off">Save poster</button>
<button type="button" class="col btn btn-danger ms-1" @onclick="CancelPoster" disabled=@(!Id.HasValue) autocomplete="off">Drop changes</button>
</div>
</div>
}
else
{
if (!string.IsNullOrWhiteSpace(_actualPosterBase64))
{
<button id="posterButtons" type="button" class="btn btn-danger form-control mt-1" @onclick="DeletePoster" disabled=@(!Id.HasValue) autocomplete="off">Delete poster</button>
}
} }
</div> </div>
<div class="col rounded-3 panel panel-regular m-1 p-3"> <div class="col rounded-3 panel panel-regular m-1 p-3">
@@ -61,7 +74,7 @@
</div> </div>
<style> <style>
#posterInput, #posterButton { #posterInput, #posterButtons {
width: 300px; width: 300px;
} }
</style> </style>

View File

@@ -1,12 +1,23 @@
using System.Diagnostics; using System.Diagnostics;
using System.Text;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Forms;
using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Media;
using WatchIt.Website.Services.WebAPI.Media;
namespace WatchIt.Website.Components; namespace WatchIt.Website.Components;
public partial class MediaForm : ComponentBase public partial class MediaForm : ComponentBase
{ {
#region SERVICES
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
[Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
#endregion
#region PROPERTIES #region PROPERTIES
[Parameter] public Media Data { get; set; } [Parameter] public Media Data { get; set; }
@@ -33,6 +44,21 @@ public partial class MediaForm : ComponentBase
#region PRIVATE METHODS #region PRIVATE METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await MediaWebAPIService.GetPoster(Id.Value, (data) =>
{
_actualPosterBase64 = Encoding.UTF8.GetString(data.Image);
_actualPosterMediaType = data.MimeType;
_posterBase64 = _actualPosterBase64;
_posterMediaType = _actualPosterMediaType;
});
StateHasChanged();
}
}
private async Task LoadPoster(InputFileChangeEventArgs args) private async Task LoadPoster(InputFileChangeEventArgs args)
{ {
if (args.File.ContentType.StartsWith("image")) if (args.File.ContentType.StartsWith("image"))
@@ -53,7 +79,41 @@ public partial class MediaForm : ComponentBase
private async Task SavePoster() private async Task SavePoster()
{ {
throw new NotImplementedException(); void SuccessAction()
{
_actualPosterBase64 = _posterBase64;
_actualPosterMediaType = _posterMediaType;
_posterChanged = false;
}
MediaPosterRequest data = new MediaPosterRequest
{
Image = Encoding.UTF8.GetBytes(_posterBase64),
MimeType = _posterMediaType
};
await MediaWebAPIService.PutPoster(Id.Value, data, SuccessAction);
}
private async Task DeletePoster()
{
void SuccessAction()
{
_actualPosterBase64 = null;
_actualPosterMediaType = null;
_posterChanged = false;
_posterBase64 = null;
_posterMediaType = null;
}
await MediaWebAPIService.DeletePoster(Id.Value, SuccessAction);
}
private void CancelPoster()
{
_posterBase64 = _actualPosterBase64;
_posterMediaType = _actualPosterMediaType;
_posterChanged = false;
} }
#endregion #endregion

View File

@@ -48,8 +48,18 @@
</div> </div>
<style> <style>
html {
height: 100%;
}
body { body {
background: url('@_background') no-repeat center center fixed; background-image: url('@_background');
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
} }
.logo, .main-button { .logo, .main-button {

View File

@@ -108,8 +108,18 @@
<style> <style>
html {
height: 100%;
}
body { body {
background: url('@(_background)') no-repeat center center fixed; background-image: url('@_background');
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
} }
.logo { .logo {

View File

@@ -0,0 +1,6 @@
@page "/movies/{id:long}
@code {
}

View File

@@ -0,0 +1,7 @@
using Microsoft.AspNetCore.Components;
namespace WatchIt.Website.Pages;
public partial class MovieDataPage : ComponentBase
{
}

View File

@@ -0,0 +1 @@