Skip to content

Commit

Permalink
Adding update modal
Browse files Browse the repository at this point in the history
fix async for Artist_artistsWorksList
remove boilerplate code
clean up console statements
  • Loading branch information
czf committed Jan 25, 2021
1 parent 4b456a0 commit ca5fc21
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ public partial class ChartComponentHeaderButtons : ComponentBase
private async Task InvokeButtonStateEvent(MouseEventArgs mouseEventArgs, EventCallback callback, HeaderButtonState buttonState)
{
HeaderButtonState selected = null;
Console.WriteLine("invoke state event");
foreach (var state in HeaderButtonConfigs)
{
Console.WriteLine($"text:{state.Text} color:{state.ButtonColor}");
state.ButtonColor = state == buttonState ? Color.Secondary : Color.Primary;
state.Active = state == buttonState;
if( state == buttonState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public DashboardPieChartComponent()

public async Task RefreshChartData()
{
Console.WriteLine("refresh picharet");
IEnumerable<DashboardChartData> newDatas = await GenerateChartDatas.Invoke();
await Chart.Clear();
await Chart.AddLabels(newDatas.Select(x => x.Label).ToArray());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


<Modal @ref="ApplicationUpdate" Closing="@((args) => args.Cancel = true)">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalBody>

<Paragraph>
This application has an update. Reload the page to get it.
</Paragraph>



</ModalBody>
<ModalFooter>
</ModalFooter>
</ModalContent>

</Modal>


Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Components;
using RadiocomDataViewApp.Interfaces;

namespace RadiocomDataViewApp.Components.Sitewide
{
public partial class ApplicationUpdateModal : ComponentBase
{
private Modal ApplicationUpdate;

[Inject]
public IUpdateService UpdateService { get; set; }


protected override async Task OnParametersSetAsync()
{

await base.OnParametersSetAsync();

UpdateService.OnWelcomeHasChanged += WelcomeHasChanged;
}

private void WelcomeHasChanged()
{
ApplicationUpdate.Show();
}
}
}
24 changes: 2 additions & 22 deletions RadiocomDataViewApp/Components/Sitewide/WelcomeModal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,15 @@ public partial class WelcomeModal : ComponentBase
private bool _hasVisited;


protected override void OnAfterRender(bool firstRender)
{
//base.OnAfterRender(firstRender);
//if (firstRender)
//{
// Welcome.Show();
//}
}

private Task ClosedModal()
{
Task visted = VisitService.SetVisitedAsync();
return visted;
}

//private async Task ClosedModal()
//{
//
//}

private void CloseClick() {
private void CloseClick()
{


Welcome.Hide();
Expand All @@ -66,7 +54,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await base.OnAfterRenderAsync(firstRender);
if (!_hasVisited)
{
Console.WriteLine("after");
Welcome.Show();
}

Expand All @@ -75,12 +62,5 @@ protected override async Task OnAfterRenderAsync(bool firstRender)



//public override async Task SetParametersAsync(ParameterView parameters)
//{

// await base.SetParametersAsync(parameters);
// _hasVisited = await VisitService.HasVisitedAsync();

//}
}
}
12 changes: 12 additions & 0 deletions RadiocomDataViewApp/Interfaces/IUpdateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RadiocomDataViewApp.Interfaces
{
public interface IUpdateService
{
public event Action OnWelcomeHasChanged;
}
}
14 changes: 9 additions & 5 deletions RadiocomDataViewApp/Pages/Artist_ArtistsWorksList.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@page "/artist/{ArtistId:int}/artistworks"
@{
}
<h3>All Songs by @_artistName</h3>

@if (_artistWorkInfos != null)
{

<ListComponent TItem="ArtistWorkDisplay" Items="@_artistWorkInfos.Select(x=> new ArtistWorkDisplay(x)).OrderBy(x => x.Name)" ListItemHrefGenerator="HrefGenerator" />
<h3>All Songs by @_artistName</h3>
<ListComponent TItem="ArtistWorkDisplay" Items="@_artistWorkInfos.Select(x => new ArtistWorkDisplay(x)).OrderBy(x => x.Name)" ListItemHrefGenerator="HrefGenerator" />
}
else
{
<p>Loading...</p>
}
9 changes: 5 additions & 4 deletions RadiocomDataViewApp/Pages/Artist_ArtistsWorksList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public partial class Artist_ArtistsWorksList : ComponentBase
private string _artistName;
private static readonly Func<ArtistWorkDisplay, string> HrefGenerator = item => $"artistwork/{item.Id}";
private IEnumerable<ArtistWorkInfo> _artistWorkInfos;
protected override async Task OnParametersSetAsync()
protected override Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
_artistWorkInfos = await RadiocomArtistWorkRepository.GetArtist_ArtistWorks(ArtistId);
_artistName = _artistWorkInfos.FirstOrDefault()?.ArtistInfo.Name;
return base.OnParametersSetAsync().ContinueWith(
x => InvokeAsync(async () => _artistWorkInfos = await RadiocomArtistWorkRepository.GetArtist_ArtistWorks(ArtistId)))
.Unwrap()
.ContinueWith(x => _artistName = _artistWorkInfos.FirstOrDefault()?.ArtistInfo.Name);
}
}
}
16 changes: 0 additions & 16 deletions RadiocomDataViewApp/Pages/Counter.razor

This file was deleted.

55 changes: 0 additions & 55 deletions RadiocomDataViewApp/Pages/FetchData.razor

This file was deleted.

7 changes: 7 additions & 0 deletions RadiocomDataViewApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static async Task Main(string[] args)
DateTime welcomeDate = builder.Configuration.GetValue<DateTime>(CONFIGKEY_WELCOME_DATE);
return new VisitService(x.GetService<ILocalStorageService>(), welcomeDate);
});
builder.Services.AddScoped<IUpdateService>(x =>
{
DateTime welcomeDate = builder.Configuration.GetValue<DateTime>(CONFIGKEY_WELCOME_DATE);
return new UpdateService(x.GetService<HttpClient>(), welcomeDate);
});


builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddBlazoredLocalStorage();

Expand Down
74 changes: 74 additions & 0 deletions RadiocomDataViewApp/Services/UpdateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;
using RadiocomDataViewApp.Interfaces;

namespace RadiocomDataViewApp.Services
{
public class UpdateService : IUpdateService, IAsyncDisposable, IDisposable
{
private readonly HttpClient _httpClient;
private readonly DateTime _welcomeTime;

private readonly Timer _welcomeTimer;
private bool disposedValue;
private readonly Random _random;

public UpdateService(HttpClient httpClient, DateTime welcomeTime)
{
_httpClient = httpClient;
_welcomeTime = welcomeTime;
_random = new Random();

_welcomeTimer = new Timer(HasApplicationUpdate, null, TimeSpan.FromHours(1), TimeSpan.FromHours(5));
}

public event Action OnWelcomeHasChanged;

private async void HasApplicationUpdate(object state)
{

bool welcomeHasChanged = await _httpClient.GetFromJsonAsync<ApplicationUpdateCheck>("/appsettings.json?r=" + _random.Next())
.ContinueWith(x => _welcomeTime != x.Result.welcome);
if (welcomeHasChanged)
{
OnWelcomeHasChanged?.Invoke();
}
}



private class ApplicationUpdateCheck
{
public DateTime welcome { get; set; }
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_welcomeTimer.Dispose();
}

disposedValue = true;
}
}

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

public ValueTask DisposeAsync()
{
return ((IAsyncDisposable)_welcomeTimer).DisposeAsync();
}
}
}
1 change: 0 additions & 1 deletion RadiocomDataViewApp/Shared/LayoutSiderContentNavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

async Task AboutClick()
{
Console.WriteLine("about");
await VisitService.ClearVisitedStateAsync();
StateHasChanged();
}
Expand Down
1 change: 1 addition & 0 deletions RadiocomDataViewApp/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@Body
</div>
<WelcomeModal/>
<ApplicationUpdateModal/>
</LayoutContent>
</Layout>
</Layout>
Expand Down
1 change: 0 additions & 1 deletion RadiocomDataViewApp/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"version": 1201234,
"welcome": "2021-01-24T00:00:00.000-08:00"
}
9 changes: 2 additions & 7 deletions RadiocomDataViewApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
Expand All @@ -35,15 +35,10 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

<script src="_content/Blazorise.Charts/blazorise.charts.js"></script>

<script src="_framework/blazor.webassembly.js"></script>
<script type="text/javascript">
function foo(a, b) {
console.log(a);
console.log(b);

}
(function () {
console.log("plugin");
Chart.plugins.register({
afterEvent: function (chartInstance, chartEvent) {
var canvas = chartInstance.chart.canvas;
Expand Down

0 comments on commit ca5fc21

Please sign in to comment.