From eca872b97fef361acb58640a850e24cda40e3555 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 7 May 2024 14:53:20 +0200 Subject: [PATCH 1/4] added real color picker, cursor size selector --- .../Local/LocalDrawingSessionActor.cs | 2 +- src/DrawTogether/Components/App.razor | 6 ++ src/DrawTogether/Components/Draw/Circle.razor | 2 +- src/DrawTogether/Components/Pages/Paint.razor | 51 ++++++++------ .../Components/Pages/Weather.razor | 67 ------------------- src/DrawTogether/Program.cs | 2 + 6 files changed, 41 insertions(+), 89 deletions(-) delete mode 100644 src/DrawTogether/Components/Pages/Weather.razor diff --git a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs index 6dd1a35..310bed7 100644 --- a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs +++ b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs @@ -189,7 +189,7 @@ protected override void PreStart() { AttemptToSubscribe(); - Context.SetReceiveTimeout(TimeSpan.FromMinutes(2)); + Context.SetReceiveTimeout(TimeSpan.FromMinutes(15)); var (sourceRef, source) = Source.ActorRef(1000, OverflowStrategy.DropHead) .PreMaterialize(_materializer); diff --git a/src/DrawTogether/Components/App.razor b/src/DrawTogether/Components/App.razor index c31e25b..67b030b 100644 --- a/src/DrawTogether/Components/App.razor +++ b/src/DrawTogether/Components/App.razor @@ -9,12 +9,18 @@ + + + + + + diff --git a/src/DrawTogether/Components/Draw/Circle.razor b/src/DrawTogether/Components/Draw/Circle.razor index 133ca5c..b496ffa 100644 --- a/src/DrawTogether/Components/Draw/Circle.razor +++ b/src/DrawTogether/Components/Draw/Circle.razor @@ -5,7 +5,7 @@ @code { - [Parameter] public int radius { get; set; } = 10; + [Parameter] public int radius { get; set; } [Parameter] public string borderColor { get; set; } = "#eee"; diff --git a/src/DrawTogether/Components/Pages/Paint.razor b/src/DrawTogether/Components/Pages/Paint.razor index 2331579..76299a9 100644 --- a/src/DrawTogether/Components/Pages/Paint.razor +++ b/src/DrawTogether/Components/Pages/Paint.razor @@ -19,21 +19,36 @@ @inject IRequiredActor LocalDrawingSessionActor; @attribute [Authorize] +

Paint!

+ + + + + + + + Cursor Size + + + + +
+ + + @foreach (var connectedStroke in Strokes.Values) + { + + } + +
+
+
+ + - - -
- - - @foreach (var connectedStroke in Strokes.Values) - { - - } - -
    @@ -143,7 +158,7 @@ break; case DrawingSessionEvents.StrokesCleared: Strokes.Clear(); - break; + break; default: throw new ArgumentOutOfRangeException(nameof(item)); } @@ -155,7 +170,8 @@ double cX = 110.0d; double cY = 110.0d; - private Color _color = new("black"); + private string _colorString = "black"; + private Color _color => new(_colorString); private GreaterThanZeroInteger _cursorSize = new(8); private string mousePointerMessage = "foo"; @@ -193,12 +209,7 @@ OnNext(new Point(e.OffsetX, e.OffsetY)); } } - - private void UpdateColor(string color) - { - _color = new Color(color); - } - + private void UpdateCursorSize(int cursorSize) { _cursorSize = new GreaterThanZeroInteger(cursorSize); diff --git a/src/DrawTogether/Components/Pages/Weather.razor b/src/DrawTogether/Components/Pages/Weather.razor deleted file mode 100644 index f31f2ee..0000000 --- a/src/DrawTogether/Components/Pages/Weather.razor +++ /dev/null @@ -1,67 +0,0 @@ -@page "/weather" -@attribute [StreamRendering] - -Weather - -

    Weather

    - -

    This component demonstrates showing data.

    - -@if (forecasts == null) -{ -

    - Loading... -

    -} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
    DateTemp. (C)Temp. (F)Summary
    @forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
    -} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - // Simulate asynchronous loading to demonstrate streaming rendering - await Task.Delay(500); - - var startDate = DateOnly.FromDateTime(DateTime.Now); - var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; - forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = summaries[Random.Shared.Next(summaries.Length)] - }).ToArray(); - } - - private class WeatherForecast - { - public DateOnly Date { get; set; } - public int TemperatureC { get; set; } - public string? Summary { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } - -} \ No newline at end of file diff --git a/src/DrawTogether/Program.cs b/src/DrawTogether/Program.cs index 42caa0a..3e25694 100644 --- a/src/DrawTogether/Program.cs +++ b/src/DrawTogether/Program.cs @@ -7,6 +7,7 @@ using DrawTogether.Data; using DrawTogether.Email; using Microsoft.AspNetCore.ResponseCompression; +using MudBlazor.Services; var builder = WebApplication.CreateBuilder(args); @@ -16,6 +17,7 @@ // If you also want WebAssembly SSR, include this line: builder.Services.AddServerSideBlazor(); +builder.Services.AddMudServices(); builder.Services.AddCascadingAuthenticationState(); builder.Services.AddScoped(); From 5345d82718424ebb7e08f9d41462010b65620d86 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 7 May 2024 14:56:07 +0200 Subject: [PATCH 2/4] redirect to home if the stream dies out --- .../Local/LocalDrawingSessionActor.cs | 2 +- src/DrawTogether/Components/Pages/Paint.razor | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs index 310bed7..6dd1a35 100644 --- a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs +++ b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs @@ -189,7 +189,7 @@ protected override void PreStart() { AttemptToSubscribe(); - Context.SetReceiveTimeout(TimeSpan.FromMinutes(15)); + Context.SetReceiveTimeout(TimeSpan.FromMinutes(2)); var (sourceRef, source) = Source.ActorRef(1000, OverflowStrategy.DropHead) .PreMaterialize(_materializer); diff --git a/src/DrawTogether/Components/Pages/Paint.razor b/src/DrawTogether/Components/Pages/Paint.razor index 76299a9..5e816eb 100644 --- a/src/DrawTogether/Components/Pages/Paint.razor +++ b/src/DrawTogether/Components/Pages/Paint.razor @@ -31,7 +31,7 @@ Cursor Size - +
    @@ -47,9 +47,6 @@ - - -
      @foreach (var u in ConnectedUsers) @@ -138,6 +135,9 @@ while (!_shutdownCts.IsCancellationRequested && await _eventStream.WaitToReadAsync(_shutdownCts.Token)) while (_eventStream.TryRead(out var evt)) HandleEvent(evt); + + // navigate us to home if the stream dies out + NavigationManager.NavigateTo("/"); } private void HandleEvent(IDrawingSessionEvent item) @@ -209,7 +209,7 @@ OnNext(new Point(e.OffsetX, e.OffsetY)); } } - + private void UpdateCursorSize(int cursorSize) { _cursorSize = new GreaterThanZeroInteger(cursorSize); From 3af810bbcf61880726d54cec835b2d8f8f8c14f9 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 7 May 2024 14:56:29 +0200 Subject: [PATCH 3/4] bump receive timeout to 20 minutes --- src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs index 6dd1a35..15d4f87 100644 --- a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs +++ b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs @@ -189,7 +189,7 @@ protected override void PreStart() { AttemptToSubscribe(); - Context.SetReceiveTimeout(TimeSpan.FromMinutes(2)); + Context.SetReceiveTimeout(TimeSpan.FromMinutes(20)); var (sourceRef, source) = Source.ActorRef(1000, OverflowStrategy.DropHead) .PreMaterialize(_materializer); From 05fd02c0a723f728bbdcb3297e5cc53a204b3a63 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 7 May 2024 15:30:41 +0200 Subject: [PATCH 4/4] final cleanup on the UI --- .../Local/LocalDrawingSessionActor.cs | 2 +- src/DrawTogether/Components/Pages/Paint.razor | 39 +++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs index 15d4f87..4d08290 100644 --- a/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs +++ b/src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs @@ -194,7 +194,7 @@ protected override void PreStart() .PreMaterialize(_materializer); _debouncer = sourceRef; - source.GroupedWithin(25, TimeSpan.FromMilliseconds(75)) + source.GroupedWithin(10, TimeSpan.FromMilliseconds(75)) .Select(c => TransmitActions(c.ToList())) .SelectMany(c => c) .SelectAsync(1, async c => diff --git a/src/DrawTogether/Components/Pages/Paint.razor b/src/DrawTogether/Components/Pages/Paint.razor index 5e816eb..6c51200 100644 --- a/src/DrawTogether/Components/Pages/Paint.razor +++ b/src/DrawTogether/Components/Pages/Paint.razor @@ -20,16 +20,28 @@ @attribute [Authorize] -

      Paint!

      +

      Paint with [@ConnectedUsers.Count] People

      + + Connected Users: +
        + @foreach (var user in ConnectedUsers) + { +
      • @user.IdentityName
      • + } +
      +
      - + - + Cursor Size + + + @@ -46,22 +58,6 @@ - -
      -
        - @foreach (var u in ConnectedUsers) - { -
      1. @u.IdentityName
      2. - } -
      -
      - -

      @mousePointerMessage

      - -

      @blazorHubDebugMessage

      - - - @code { [Parameter] public string SessionId { get; set; } @@ -134,7 +130,11 @@ Debug.Assert(_eventStream != null, nameof(_eventStream) + " != null"); while (!_shutdownCts.IsCancellationRequested && await _eventStream.WaitToReadAsync(_shutdownCts.Token)) while (_eventStream.TryRead(out var evt)) + { HandleEvent(evt); + await InvokeAsync(StateHasChanged); + } + // navigate us to home if the stream dies out NavigationManager.NavigateTo("/"); @@ -164,7 +164,6 @@ } LastUpdate = DateTime.UtcNow; - StateHasChanged(); }