From 1063262625f507b7b35e0d4b2ca3d6f5210038f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 3 Jun 2022 14:22:50 +0200 Subject: [PATCH] #387 - Refactor release notes to a component. --- .../Components/PwaUpdate.razor | 2 +- .../Components/PwaUpdate.razor.cs | 9 ----- .../Components/ReleaseNotes.cs | 37 +++++++++++++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 src/Money.Blazor.Host/Components/ReleaseNotes.cs diff --git a/src/Money.Blazor.Host/Components/PwaUpdate.razor b/src/Money.Blazor.Host/Components/PwaUpdate.razor index bf691d67..59caeca5 100644 --- a/src/Money.Blazor.Host/Components/PwaUpdate.razor +++ b/src/Money.Blazor.Host/Components/PwaUpdate.razor @@ -16,7 +16,7 @@ - @ReleaseNotes + } else diff --git a/src/Money.Blazor.Host/Components/PwaUpdate.razor.cs b/src/Money.Blazor.Host/Components/PwaUpdate.razor.cs index ef602aed..d6aaa2e4 100644 --- a/src/Money.Blazor.Host/Components/PwaUpdate.razor.cs +++ b/src/Money.Blazor.Host/Components/PwaUpdate.razor.cs @@ -17,8 +17,6 @@ namespace Money.Components public partial class PwaUpdate : IDisposable, IEventHandler { - private readonly HttpClient http = new HttpClient(); - [Inject] protected IEventHandlerCollection EventHandlers { get; set; } @@ -37,11 +35,7 @@ public partial class PwaUpdate : IDisposable, protected override void OnInitialized() { base.OnInitialized(); - EventHandlers.Add(this); - http.BaseAddress = new Uri(Navigator.UrlOrigin()); - - //_ = ((IEventHandler)this).HandleAsync(null); } public void Dispose() @@ -52,9 +46,6 @@ public void Dispose() async Task IEventHandler.HandleAsync(PwaUpdateable payload) { IsUpdateable = true; - - ReleaseNotes = new MarkupString(await http.GetStringAsync("/release-notes.html")); - StateHasChanged(); } } diff --git a/src/Money.Blazor.Host/Components/ReleaseNotes.cs b/src/Money.Blazor.Host/Components/ReleaseNotes.cs new file mode 100644 index 00000000..aaece366 --- /dev/null +++ b/src/Money.Blazor.Host/Components/ReleaseNotes.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Rendering; +using Money.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace Money.Components +{ + public partial class ReleaseNotes : ComponentBase + { + [Inject] + protected Navigator Navigator { get; set; } + + private readonly HttpClient http = new HttpClient(); + private string value; + + protected override async Task OnInitializedAsync() + { + http.BaseAddress = new Uri(Navigator.UrlOrigin()); + + await base.OnInitializedAsync(); + value = await http.GetStringAsync("/release-notes.html"); + } + + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + + builder.AddMarkupContent(0, value); + } + } +}