Skip to content

Commit

Permalink
#387 - Refactor release notes to a component.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 3, 2022
1 parent b941f19 commit 1063262
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Components/PwaUpdate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
</div>

@ReleaseNotes
<ReleaseNotes />
</LayoutView>
}
else
Expand Down
9 changes: 0 additions & 9 deletions src/Money.Blazor.Host/Components/PwaUpdate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace Money.Components
public partial class PwaUpdate : IDisposable,
IEventHandler<PwaUpdateable>
{
private readonly HttpClient http = new HttpClient();

[Inject]
protected IEventHandlerCollection EventHandlers { get; set; }

Expand All @@ -37,11 +35,7 @@ public partial class PwaUpdate : IDisposable,
protected override void OnInitialized()
{
base.OnInitialized();

EventHandlers.Add<PwaUpdateable>(this);
http.BaseAddress = new Uri(Navigator.UrlOrigin());

//_ = ((IEventHandler<PwaUpdateable>)this).HandleAsync(null);
}

public void Dispose()
Expand All @@ -52,9 +46,6 @@ public void Dispose()
async Task IEventHandler<PwaUpdateable>.HandleAsync(PwaUpdateable payload)
{
IsUpdateable = true;

ReleaseNotes = new MarkupString(await http.GetStringAsync("/release-notes.html"));

StateHasChanged();
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/Money.Blazor.Host/Components/ReleaseNotes.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 1063262

Please sign in to comment.