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

v 0.6.1 #56

Merged
merged 17 commits into from
Apr 6, 2023
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
24 changes: 24 additions & 0 deletions src/iRLeagueManager.Web/Components/DisplayLeague.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@using iRLeagueApiCore.Common.Models;
<label class="@(MuteTextOnFallback && string.IsNullOrEmpty(League?.NameFull) ? "text-muted" : "")">@GetLeagueName()</label>

@code {
[Parameter]
public LeagueModel? League { get; set; }
[Parameter]
public string Fallback { get; set; } = string.Empty;
[Parameter]
public bool MuteTextOnFallback { get; set; } = false;

private string GetLeagueName()
{
if (League is null)
{
return Fallback;
}
if (string.IsNullOrEmpty(League.NameFull))
{
return League.Name;
}
return League.NameFull;
}
}
20 changes: 7 additions & 13 deletions src/iRLeagueManager.Web/Components/EditModalBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MvvmBlazor.Components;
using Newtonsoft.Json.Linq;

namespace iRLeagueManager.Web.Components;

Expand All @@ -22,20 +23,8 @@ public class EditModalBase<TViewModel, TModel> : MvvmComponentBase where TViewMo
[CascadingParameter]
public IModalService ModalService { get; set; } = default!;

private TModel model = default!;
[Parameter, EditorRequired]
public TModel Model
{
get => model;
set
{
if (EqualityComparer<TModel>.Default.Equals(model, value) == false)
{
model = value;
Vm.SetModel(model);
}
}
}
public TModel Model { get; set; } = default!;

[Parameter]
public Func<TViewModel, CancellationToken, Task<StatusResult>>? OnSubmit { get; set; }
Expand All @@ -60,6 +49,11 @@ protected override void OnParametersSet()
_ = ModalInstance ?? throw BlazorParameterNullException.New(this, ModalInstance);
_ = ModalService ?? throw BlazorParameterNullException.New(this, ModalService);
_ = Model ?? throw BlazorParameterNullException.New(this, Model);

if (EqualityComparer<TModel>.Default.Equals(Model, Vm.GetModel()) == false)
{
Vm.SetModel(Model);
}
}

protected virtual async Task Submit()
Expand Down
7 changes: 3 additions & 4 deletions src/iRLeagueManager.Web/Components/EventSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<option value="@(index)">@((index + 1).ToString("00")). @(@event.Date.ToString("dd.MM.yy")): @(@event.TrackName)@(@event.ConfigName == "-" ? "" : $" - {@event.ConfigName}")</option>
}
</select>
<button class="btn btn-outline-secondary" type="button" @onclick=EventMovePrevious disabled=@(SelectedIndex == 0)><span class="oi oi-chevron-left"></span></button>
<button class="btn btn-outline-secondary" type="button" @onclick=EventMoveNext disabled=@(SelectedIndex == Events.Count-1)><span class="oi oi-chevron-right"></span></button>
<button class="btn btn-outline-secondary" type="button" @onclick=EventMovePrevious disabled="@(SelectedIndex == 0)"><span class="oi oi-chevron-left"></span></button>
<button class="btn btn-outline-secondary" type="button" @onclick=EventMoveNext disabled="@(SelectedIndex == Events.Count-1)"><span class="oi oi-chevron-right"></span></button>
</div>

@code {
Expand Down Expand Up @@ -47,8 +47,7 @@

private ObservableCollection<EventViewModel> Events => EventList.EventList;

[Parameter]
public EventViewModel? Selected
private EventViewModel? Selected
{
get => eventList?.Selected;
set
Expand Down
102 changes: 0 additions & 102 deletions src/iRLeagueManager.Web/Components/InputMemberSelect.razor

This file was deleted.

64 changes: 64 additions & 0 deletions src/iRLeagueManager.Web/Components/SeasonSelect.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@using iRLeagueApiCore.Common.Models;
@implements IDisposable
@inject LeagueApiService ApiService
@inject SharedStateService Shared

<select @bind="SelectedSeasonId" class="form-select" @attributes=AdditionalAttributes @onclick:stopPropagation>
@foreach (var season in Shared.SeasonList)
{
<option value="@season.SeasonId" class="nav-option">@season.SeasonName</option>
}
</select>

@code {
[Parameter(CaptureUnmatchedValues = true)]
public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }
[Parameter]
public EventCallback<SeasonModel?> SeasonChanged { get; set; }

private long selectedSeasonId;
private long SelectedSeasonId
{
get => selectedSeasonId;
set
{
if (selectedSeasonId != value)
{
selectedSeasonId = value;
_ = OnSeasonSelectChanged(value);
}
}
}

protected override void OnInitialized()
{
selectedSeasonId = Shared.SeasonId;
Shared.StateChanged += SharedStateChanged;
}

private async Task OnSeasonSelectChanged(long seasonId)
{
if (Shared.LeagueName == null || seasonId == 0)
{
return;
}
await ApiService.SetCurrentSeasonAsync(Shared.LeagueName, seasonId);
await SeasonChanged.InvokeAsync(Shared.SeasonList.FirstOrDefault(x => x.SeasonId == seasonId));
}

private async void SharedStateChanged(object? sender, EventArgs e)
{
var previousSeasonId = selectedSeasonId;
selectedSeasonId = Shared.SeasonId;
await InvokeAsync(StateHasChanged);
if (previousSeasonId != selectedSeasonId)
{
await SeasonChanged.InvokeAsync(Shared.SeasonList.FirstOrDefault(x => x.SeasonId == selectedSeasonId));
}
}

public void Dispose()
{
Shared.StateChanged -= SharedStateChanged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@using iRLeagueApiCore.Common.Models;
@inherits EditModalBase<LeagueViewModel, LeagueModel>

<EditForm Model=@Model>
<InputGroup Label="Full Name">
<InputText class="form-control" @bind-Value=Model.NameFull />
</InputGroup>
<CancelSubmitButtons OnSubmit=Submit OnCancel=Cancel />
</EditForm>

@code {

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using iRLeagueApiCore.Common.Enums
@using iRLeagueApiCore.Common.Models
@inherits MvvmComponentBase
@inject ResultFiltersViewModel vm;
@inject ResultFiltersViewModel vm

@foreach(var filter in vm.Filters)
{
Expand Down
19 changes: 6 additions & 13 deletions src/iRLeagueManager.Web/Components/Settings/EditTeamModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,8 @@
[CascadingParameter]
public IModalService ModalService { get; set; } = default!;

private TeamModel model = default!;
[Parameter]
public TeamModel Model
{
get => model;
set
{
if (EqualityComparer<TeamModel>.Default.Equals(model, value) == false)
{
model = value;
vm.SetModel(model);
}
}
}
public TeamModel Model { get; set; } = default!;
[Parameter]
public IEnumerable<MemberInfoModel> LeagueMembers { get; set; } = default!;

Expand All @@ -84,6 +72,11 @@
_ = ModalService ?? throw BlazorParameterNullException.New(this, ModalService);
_ = Model ?? throw BlazorParameterNullException.New(this, Model);
_ = LeagueMembers ?? throw BlazorParameterNullException.New(this, LeagueMembers);

if (EqualityComparer<TeamModel>.Default.Equals(Model, vm.GetModel()) == false)
{
vm.SetModel(Model);
}
}

private async Task<IEnumerable<MemberInfoModel>> SearchMembers(string searchString)
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueManager.Web/Data/LeagueApiClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class LeagueApiClientFactory
public LeagueApiClientFactory(IConfiguration configuration, ILoggerFactory loggerFactory, IHttpClientFactory httpClientFactory,
ILocalStorageService localStorage, ITokenStore tokenStore, JsonSerializerOptions jsonOptions)
{
baseAddress = configuration["APIServer"];
baseAddress = configuration["APIServer"] ?? string.Empty;
this.loggerFactory = loggerFactory;
logger = loggerFactory.CreateLogger<LeagueApiClientFactory>();
this.httpClientFactory = httpClientFactory;
Expand Down
11 changes: 8 additions & 3 deletions src/iRLeagueManager.Web/Data/LeagueApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ public async Task SetCurrentLeagueAsync(string leagueName)
Shared.SeasonId = 0;
Shared.SeasonName = string.Empty;
Shared.SeasonFinished = true;
var result = await CurrentLeague.Seasons().Get();
if (result.Success && result.Content is not null)
var leagueResult = await CurrentLeague.Get();
if (leagueResult.Success && leagueResult.Content is not null)
{
Shared.LeagueInfo = leagueResult.Content;
}
var seasonResult = await CurrentLeague.Seasons().Get();
if (seasonResult.Success && seasonResult.Content is not null)
{
var seasons = result.Content;
var seasons = seasonResult.Content;
Shared.SeasonList = new ObservableCollection<SeasonModel>(seasons);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/iRLeagueManager.Web/Data/LeeagueModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace iRLeagueManager.Web.Data;

internal class LeeagueModel
{
}
4 changes: 4 additions & 0 deletions src/iRLeagueManager.Web/Data/SharedStateService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using iRLeagueApiCore.Common.Models;
using iRLeagueManager.Web.ViewModels;
using System.Runtime.CompilerServices;

namespace iRLeagueManager.Web.Data;
Expand Down Expand Up @@ -31,6 +32,9 @@ public sealed class SharedStateService
private TimeZoneInfo localTimeZone;
public TimeZoneInfo LocalTimeZone { get => localTimeZone; set => Set(ref localTimeZone, value); }

private LeagueModel? leagueInfo;
public LeagueModel? LeagueInfo { get => leagueInfo; set => Set(ref leagueInfo, value); }

public SharedStateService()
{
seasonList = new ObservableCollection<SeasonModel>();
Expand Down
6 changes: 5 additions & 1 deletion src/iRLeagueManager.Web/Pages/Leagues.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
{
<tr>
<td>@Bind(league, x => x.LeagueId)</td>
<td><NavLink class="nav-link" href="@($"./{@Bind(league, x => x.LeagueName)}/Seasons")">@Bind(league, x => x.LeagueName)</NavLink></td>
<td>
<NavLink class="nav-link" href="@($"./{@Bind(league, x => x.LeagueName)}/Seasons")">
<DisplayLeague League=league.GetModel() />
</NavLink>
</td>
</tr>
}
</tbody>
Expand Down
Loading