Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] UI improvements #37

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DrawTogether.Actors/Local/LocalDrawingSessionActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ protected override void PreStart()
{
AttemptToSubscribe();

Context.SetReceiveTimeout(TimeSpan.FromMinutes(2));
Context.SetReceiveTimeout(TimeSpan.FromMinutes(20));
var (sourceRef, source) = Source.ActorRef<AddPointToConnectedStroke>(1000, OverflowStrategy.DropHead)
.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 =>
Expand Down
6 changes: 6 additions & 0 deletions src/DrawTogether/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
<link rel="stylesheet" href="app.css"/>
<link rel="stylesheet" href="DrawTogether.styles.css"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<HeadOutlet/>
</head>

<body>
<Routes @rendermode="@RenderModeForPage"/>
<script src="_framework/blazor.web.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<MudThemeProvider/>
<MudDialogProvider/>
<MudSnackbarProvider/>
</body>

</html>
Expand Down
2 changes: 1 addition & 1 deletion src/DrawTogether/Components/Draw/Circle.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

@code {

[Parameter] public int radius { get; set; } = 10;
[Parameter] public int radius { get; set; }

[Parameter] public string borderColor { get; set; } = "#eee";

[Parameter] public string fillColor { get; set; } = "#eee";

[Parameter] public string cursorId { get; set; }

Check warning on line 14 in src/DrawTogether/Components/Draw/Circle.razor

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

Non-nullable property 'cursorId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 14 in src/DrawTogether/Components/Draw/Circle.razor

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

Non-nullable property 'cursorId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 14 in src/DrawTogether/Components/Draw/Circle.razor

View workflow job for this annotation

GitHub Actions / Test-windows-latest

Non-nullable property 'cursorId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 14 in src/DrawTogether/Components/Draw/Circle.razor

View workflow job for this annotation

GitHub Actions / Test-windows-latest

Non-nullable property 'cursorId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[Parameter] public double cX { get; set; }

Expand Down
84 changes: 47 additions & 37 deletions src/DrawTogether/Components/Pages/Paint.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,48 @@
@inject IRequiredActor<LocalDrawingSessionActor> LocalDrawingSessionActor;
@attribute [Authorize]

<h3>Paint!</h3>

<ColorPicker ColorValueChanged="UpdateColor"></ColorPicker>
<CursorPicker CursorSizeChanged="UpdateCursorSize"></CursorPicker>

<section id="paint" style="background-color: cornsilk; width: 900px; height: 500px;"
@onmousemove="CursorMove" @onmousedown="CursorDown" @onmouseup="CursorUp">
<svg width="900" height="500">
<Circle radius="@_cursorSize.Value" cursorId="@_currentUserId!.IdentityName" cX="@cX" cY="@cY" fillColor="@_color.HexCodeOrColorName" borderColor="@_color.HexCodeOrColorName"/>
@foreach (var connectedStroke in Strokes.Values)
{
<Curve Points="@connectedStroke.Points" Stroke="@connectedStroke.StrokeColor.HexCodeOrColorName" StrokeWidth="@connectedStroke.StrokeWidth.Value"/>
}
</svg>
</section>

<div id="active-users">
<ol>
@foreach (var u in ConnectedUsers)
{
<li>@u.IdentityName</li>
}
</ol>
</div>

<p>@mousePointerMessage</p>

<p>@blazorHubDebugMessage</p>

<button id="reset" @onclick="ResetScreen">Clear Screen</button>
<h3>Paint with [@ConnectedUsers.Count] People</h3>
<MudPaper Class="align-content-center d-flex" Elevation="0">
<MudText Typo="Typo.h6">Connected Users:</MudText>
<ul class="list-inline">
@foreach (var user in ConnectedUsers)
{
<li class="list-inline-item">@user.IdentityName</li>
}
</ul>
</MudPaper>
<MudGrid>
<MudItem xs="2">
<MudStack>
<MudPaper Elevation="0">
<MudColorPicker Label="Color" @bind-Text="_colorString" Style="@($"color: {_colorString};")" Placeholder="Select Color" PickerVariant="PickerVariant.Static"/>
</MudPaper>
<MudPaper Elevation="0">
<MudSlider Value="@_cursorSize.Value" ValueLabel="true" Min="1" Max="50" ValueChanged="@((int value) => UpdateCursorSize(value))">Cursor Size</MudSlider>
</MudPaper>
<MudPaper Elevation="0" Class="align-content-center">
<button class="btn btn-primary" id="reset" @onclick="ResetScreen">Clear Screen</button>
</MudPaper>
</MudStack>
</MudItem>
<MudItem xs="10">
<section id="paint" style="background-color: cornsilk; width: 900px; height: 500px;"
@onmousemove="CursorMove" @onmousedown="CursorDown" @onmouseup="CursorUp">
<svg width="900" height="500">
<Circle radius="@_cursorSize.Value" cursorId="@_currentUserId!.IdentityName" cX="@cX" cY="@cY" fillColor="@_color.HexCodeOrColorName" borderColor="@_color.HexCodeOrColorName"/>
@foreach (var connectedStroke in Strokes.Values)
{
<Curve Points="@connectedStroke.Points" Stroke="@connectedStroke.StrokeColor.HexCodeOrColorName" StrokeWidth="@connectedStroke.StrokeWidth.Value"/>
}
</svg>
</section>
</MudItem>
</MudGrid>

@code {

[Parameter] public string SessionId { get; set; }

Check warning on line 63 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

Non-nullable property 'SessionId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 63 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

Non-nullable property 'SessionId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 63 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-windows-latest

Non-nullable property 'SessionId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 63 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-windows-latest

Non-nullable property 'SessionId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public Dictionary<StrokeId, ConnectedStroke> Strokes { get; set; } = new();

Expand Down Expand Up @@ -122,7 +130,14 @@
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("/");
}

private void HandleEvent(IDrawingSessionEvent item)
Expand All @@ -143,23 +158,23 @@
break;
case DrawingSessionEvents.StrokesCleared:
Strokes.Clear();
break;
break;
default:
throw new ArgumentOutOfRangeException(nameof(item));
}

LastUpdate = DateTime.UtcNow;
StateHasChanged();
}


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";
private string blazorHubDebugMessage = "bar";

Check warning on line 177 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

The field 'Paint.blazorHubDebugMessage' is assigned but its value is never used

Check warning on line 177 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

The field 'Paint.blazorHubDebugMessage' is assigned but its value is never used

Check warning on line 177 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-windows-latest

The field 'Paint.blazorHubDebugMessage' is assigned but its value is never used

Check warning on line 177 in src/DrawTogether/Components/Pages/Paint.razor

View workflow job for this annotation

GitHub Actions / Test-windows-latest

The field 'Paint.blazorHubDebugMessage' is assigned but its value is never used

private void CursorDown(MouseEventArgs e)
{
Expand Down Expand Up @@ -194,11 +209,6 @@
}
}

private void UpdateColor(string color)
{
_color = new Color(color);
}

private void UpdateCursorSize(int cursorSize)
{
_cursorSize = new GreaterThanZeroInteger(cursorSize);
Expand Down
67 changes: 0 additions & 67 deletions src/DrawTogether/Components/Pages/Weather.razor

This file was deleted.

2 changes: 2 additions & 0 deletions src/DrawTogether/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DrawTogether.Data;
using DrawTogether.Email;
using Microsoft.AspNetCore.ResponseCompression;
using MudBlazor.Services;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -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<IdentityUserAccessor>();
Expand Down