Skip to content

Commit

Permalink
fixed startup crash issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed May 6, 2024
1 parent c74f759 commit f8b792b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public GetLocalActorHandle(DrawingSessionId drawingSessionId)
private readonly IMaterializer _materializer = Context.System.Materializer();
private IActorRef _debouncer = ActorRefs.Nobody;

public LocalDrawingSessionActor(DrawingSessionId drawingSessionId,
public LocalDrawingSessionActor(string drawingSessionId,
IRequiredActor<DrawingSessionActor> drawingSessionActor)
{
_drawingSessionId = drawingSessionId;
_drawingSessionId = new DrawingSessionId(drawingSessionId);
_drawingSessionActor = drawingSessionActor.ActorRef;
}

Expand Down
18 changes: 18 additions & 0 deletions src/DrawTogether/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@

<AuthorizeView>
<Authorized>
<div class="nav-item px-3">
<button class="nav-link" @onclick="Handler">
<span class="bi bi-pencil-fill-nav-menu" aria-hidden="true"></span> New Drawing
</button>>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Manage">
<span class="bi bi-person-fill-nav-menu" aria-hidden="true"></span> @context.User.Identity?.Name
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Manage">
<span class="bi bi-person-fill-nav-menu" aria-hidden="true"></span> @context.User.Identity?.Name
Expand Down Expand Up @@ -60,6 +70,8 @@
@code {
private string? _currentUrl;

protected string GetNewGuid() => Guid.NewGuid().ToString();

protected override void OnInitialized()
{
_currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
Expand All @@ -77,4 +89,10 @@
NavigationManager.LocationChanged -= OnLocationChanged;
}

private void Handler()
{
var newGuid = GetNewGuid();
NavigationManager.NavigateTo($"paint/{newGuid}");
}

}
9 changes: 5 additions & 4 deletions src/DrawTogether/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ else
<tbody>
@foreach (var session in _drawingActivities)
{
var hrefUri = $"paint/{session.Key!.SessionId}";
<tr>
<td>@session.Key.SessionId</td>
<td>@session.Key!.SessionId</td>
<td>@session.Value.ActiveUsers</td>
<td>@session.Value.LastUpdate</td>
<td>Join Button</td>
<td><MudLink Href="@hrefUri">Join Session!</MudLink></td>
</tr>
}
</tbody>
</table>
}

@code{
private Dictionary<DrawingSessionId, DrawingActivityUpdate> _drawingActivities = new();
private CancellationTokenSource _shutdownCts = new();
private readonly Dictionary<DrawingSessionId, DrawingActivityUpdate> _drawingActivities = new();
private readonly CancellationTokenSource _shutdownCts = new();

protected override async Task OnInitializedAsync()
{
Expand Down
15 changes: 5 additions & 10 deletions src/DrawTogether/Components/Pages/Paint.razor
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,15 @@

public DateTime LastUpdate { get; set; } = DateTime.UtcNow;

DrawingSessionId DrawingSessionId { get; set; }
DrawingSessionId? DrawingSessionId { get; set; }

private ChannelReader<IDrawingSessionEvent>? _eventStream = null;

private IActorRef _localActorHandle;
private IActorRef? _localActorHandle;
private readonly CancellationTokenSource _shutdownCts = new();

private ClaimsPrincipal? _user;
private UserId _currentUserId;

private record StartupTasks(Task<IActorRef> LocalHandleTask, Task<DrawingSessionState> CurrentSnapshotTask, Task<LocalDrawingSessionActor.DrawingChannelResponse> EventStreamTask)
{
Task WhenAll => Task.WhenAll(LocalHandleTask, CurrentSnapshotTask, EventStreamTask);
}
private UserId? _currentUserId;

protected override async Task OnInitializedAsync()
{
Expand Down Expand Up @@ -162,7 +157,7 @@
double cY = 110.0d;
private Color _color = new("black");
private GreaterThanZeroInteger _cursorSize = new(8);

private string mousePointerMessage = "foo";
private string blazorHubDebugMessage = "bar";

Expand Down Expand Up @@ -239,7 +234,7 @@
public async ValueTask DisposeAsync()
{
await _shutdownCts.CancelAsync();
_localActorHandle.Tell(new LocalPaintProtocol.LeavePaintSession(DrawingSessionId, _currentUserId));
if (DrawingSessionId != null && _currentUserId is not null) _localActorHandle.Tell(new LocalPaintProtocol.LeavePaintSession(DrawingSessionId, _currentUserId));
_shutdownCts.Dispose();
}

Expand Down

0 comments on commit f8b792b

Please sign in to comment.