Skip to content

Commit

Permalink
added data loading to homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed May 6, 2024
1 parent 2ed98df commit 8cfa2fb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 36 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageVersion Include="Akka.Streams" Version="1.5.20" />
<PackageVersion Include="Akka.Streams.TestKit" Version="1.5.20" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageVersion Include="MudBlazor" Version="6.19.1" />
</ItemGroup>
<!-- ASP.NET Package Versions -->
<ItemGroup>
Expand Down
12 changes: 0 additions & 12 deletions src/DrawTogether/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="auth">
<span class="bi bi-lock-nav-menu" aria-hidden="true"></span> Auth Required
Expand Down
20 changes: 0 additions & 20 deletions src/DrawTogether/Components/Pages/Counter.razor

This file was deleted.

72 changes: 69 additions & 3 deletions src/DrawTogether/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
@page "/"
@using Akka.Actor
@using Akka.Hosting
@using DrawTogether.Actors.Drawings
@using DrawTogether.Entities.Drawings
@inject IRequiredActor<AllDrawingsIndexActor> AllDrawingsIndexActor
@inject ActorSystem ActorSystem
@implements IAsyncDisposable

<PageTitle>Home</PageTitle>
<PageTitle>DrawTogether.NET</PageTitle>

<h1>Hello, world!</h1>
<h1>Active Paint Sessions</h1>
@if (_drawingActivities.Count == 0)
{
// no active paint sessions right now, would you like to start one?
<div class="center">
<strong>No active sessions right now - would you like to make one?</strong>
</div>
}
else
{
<table class="table">
<thead>
<tr>
<th>SessionId</th>
<th>Active Users</th>
<th>Last Updated</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var session in _drawingActivities)
{
<tr>
<td>@session.Key.SessionId</td>
<td>@session.Value.ActiveUsers</td>
<td>@session.Value.LastUpdate</td>
<td>Join Button</td>
</tr>
}
</tbody>
</table>
}

Welcome to your new app.
@code{
private Dictionary<DrawingSessionId, DrawingActivityUpdate> _drawingActivities = new();
private CancellationTokenSource _shutdownCts = new();

protected override async Task OnInitializedAsync()
{
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1000));
using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, _shutdownCts.Token);
var allDrawingsActor = await AllDrawingsIndexActor.GetAsync(linkedCts.Token);

var currentState = await allDrawingsActor.Ask<IReadOnlyCollection<DrawingActivityUpdate>>(DrawingIndexQueries.GetAllActiveDrawingSessions.Instance, linkedCts.Token);

// populate the current table
foreach (var drawingActivity in currentState)
{
_drawingActivities[drawingActivity.DrawingSessionId] = drawingActivity;
}

await base.OnInitializedAsync();
}

public async ValueTask DisposeAsync()
{
await _shutdownCts.CancelAsync();
_shutdownCts.Dispose();
await ValueTask.CompletedTask;
}

}
3 changes: 2 additions & 1 deletion src/DrawTogether/Components/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using DrawTogether
@using DrawTogether.Components
@using DrawTogether.Components
@using MudBlazor
1 change: 1 addition & 0 deletions src/DrawTogether/DrawTogether.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools"/>
<PackageReference Include="MudBlazor" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 8cfa2fb

Please sign in to comment.