Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Make player headshots nullable #162

Merged
merged 2 commits into from
Nov 4, 2022
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/Client/Features/Admin/AddPlayer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<MudGrid>
<MudItem lg="8" md="12">
<EditForm Model=_addPlayerForm OnValidSubmit=OnValidSubmitAsync>
<FluentValidationValidator Validator=_validator />
<FluentValidationValidator />
<MudGrid>
<MudItem xs="12">
<MudTextField @bind-Value="_addPlayerForm.Name" Label="Player Name" Variant="Variant.Text" For="@(() => _addPlayerForm.Name)" id="@nameof(_addPlayerForm.Name)" OnBlur=MapToHeadshotForm/>
Expand Down Expand Up @@ -47,7 +47,7 @@
<MudItem lg="4" xs="12" Class="d-flex justify-center align-center">
<MudGrid>
<MudItem xs="12" Class="d-flex justify-center">
<Avatar Image="@_previewHeadshotUrl" Size="Size.Large"/>
<Avatar Image="@_previewHeadshotUrl" Name=@_addPlayerForm.Name Size="Size.Large"/>
</MudItem>
<MudItem xs="12">
<EditForm Model=_playerPreviewForm OnValidSubmit=PreviewHeadshotAsync>
Expand Down
6 changes: 1 addition & 5 deletions src/Client/Features/Admin/AddPlayer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ public sealed partial class AddPlayer : IDisposable
{
[Inject] private HttpClient HttpClient { get; set; } = null!;
[Inject] private ISnackbar SnackBar { get; set; } = null!;
[Inject] private IPlayerHeadshotService PlayerHeadshotService { get; set; } = null!;

private TeamNameListResult _teamList = new();
private AddPlayerRequest _addPlayerForm = new();
private AddPlayerRequestValidator _validator = null!;
private PlayerPreviewRequest _playerPreviewForm = new();
private readonly PlayerPreviewRequest _playerPreviewForm = new();
private string _previewHeadshotUrl = string.Empty;
private bool _isPreviewButtonDisabled;
private bool _isProcessingForm;
Expand All @@ -24,8 +22,6 @@ public sealed partial class AddPlayer : IDisposable

protected override async Task OnInitializedAsync()
{
_validator = new(PlayerHeadshotService);

_teamList = await HttpClient.GetFromJsonAsync<TeamNameListResult>(AddPlayerRouteFactory.GetTeamListUri, _cts.Token) ?? new TeamNameListResult();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Client/Features/Dashboard/Shared/RankedCard.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<MudCard Style=@BackgroundColor Class="ma-1">
<MudCardHeader>
<CardHeaderAvatar>
<Avatar [email protected]></Avatar>
<Avatar [email protected] [email protected]></Avatar>
</CardHeaderAvatar>
<CardHeaderContent>
<MudText Typo="NameTypo">@RankedItem.Name</MudText>
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Features/FreeAgents/Detail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
<MudCardContent>
<MudGrid>
<MudItem lg=3 xs=12 Class="d-flex flex-column align-center">
<Avatar Image=@_result.HeadShotUrl Size=Size.Large />
<Avatar Image=@_result.HeadShotUrl Name="@_result.Name" Size=Size.Large />
<MudText Typo=Typo.h5 Align=Align.Center Color=Color.Tertiary>
@_result.Name
</MudText>
Expand Down
16 changes: 6 additions & 10 deletions src/Client/Shared/Components/Avatar.razor
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
@if(string.IsNullOrEmpty(Image))
{
<div class="mud-theme-dark pa-2 rounded-circle">
<MudIcon [email protected] Size=Size @attributes=AllOtherAttributes></MudIcon>
</div>
}
else
{
<MudAvatar Image=@Image Size=Size @attributes=AllOtherAttributes></MudAvatar>
}
<MudAvatar Image=@Image Size=Size @attributes=AllOtherAttributes>
@Initials
</MudAvatar>


@code {
[Parameter] public string? Name { get; set; }
[Parameter] public string? Image { get; set; }
[Parameter] public Size Size { get; set; } = Size.Medium;
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AllOtherAttributes { get; set; }

private string Initials => !string.IsNullOrEmpty(Name) ? string.Concat(Name.Split(" ").Select(x => x.Substring(0, 1).ToUpperInvariant())) : "UK";
}
2 changes: 1 addition & 1 deletion src/Client/Shared/Components/NameWithImage.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="d-flex align-center">
<Avatar Image=@ImageUrl Class="mr-1"></Avatar>
<Avatar Image=@ImageUrl Name=@Name class="mr-1"></Avatar>
@Name
</div>

Expand Down
5 changes: 3 additions & 2 deletions src/Server/Features/Admin/AddPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public async Task<int> Handle(AddPlayerCommand request, CancellationToken cancel
{
var headshotUrl = await _playerHeadshotService.FindPlayerHeadshotUrlAsync(request.Name, request.Position, cancellationToken);

var player = new Player(request.Name, request.Position, headshotUrl!)
var player = new Player(request.Name, request.Position)
{
ContractValue = request.ContractValue,
TeamId = request.TeamId
TeamId = request.TeamId,
HeadShotUrl = headshotUrl
};

_dbContext.Add(player);
Expand Down
Loading