Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/Groups' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
g-martin772 committed Jun 9, 2024
2 parents 32f281c + 3c84fc2 commit 77bbd2b
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 176 deletions.
42 changes: 18 additions & 24 deletions MPM-Betting.Blazor.ComponentLibrary/DesktopView/Groups.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using MPM_Betting.Services.Data
@using MPM_Betting.Blazor.ComponentLibrary.DesktopView.SmallComponents
@using Blazorise
@using LanguageExt.Pipes

Check warning on line 5 in MPM-Betting.Blazor.ComponentLibrary/DesktopView/Groups.razor

View workflow job for this annotation

GitHub Actions / qodana

Redundant using directive

Using directive is not required by the code and can be safely removed
@using Microsoft.AspNetCore.Authorization
@using MPM_Betting.Blazor.ComponentLibrary.Core
@using MPM_Betting.DataModel.User
Expand Down Expand Up @@ -33,15 +34,15 @@
}
else
{
@foreach(var group in GroupsList)
@foreach(var groupEntry in GroupsAndPlaces)
{
<div class="GroupEntry row">
<div class="col-3 GroupEntryImageBox">
<img width="60%" src="./Images/Logo_cropped.png" alt="image"/>
</div>
<div class="col-7">@group.Name</div>
<div class="col-7">@groupEntry.Item1.Name</div>
@* TODO Abfrage >:c *@
@switch(1)
@switch(groupEntry.Item2)
{
case 1:
<div class="col-2 gold">1st</div>
Expand All @@ -53,7 +54,7 @@
<div class="col-2 bronze">3rd</div>
break;
default:
<div class="col-2">4th</div>
<div class="col-2">@(groupEntry.Item2)th</div>
break;
}
</div>
Expand All @@ -66,9 +67,11 @@
[CascadingParameter] private SyncContextWithPayload<MpmUser>? UserTask { get; set; }
MpmUser? User;
public List<MpmGroup> GroupsList { get; set; }

public List<Tuple<MpmGroup, int>> GroupsAndPlaces { get; set; }

Check warning on line 70 in MPM-Betting.Blazor.ComponentLibrary/DesktopView/Groups.razor

View workflow job for this annotation

GitHub Actions / qodana

Non-nullable member is uninitialized.

Non-nullable property 'GroupsAndPlaces' is uninitialized. Consider declaring the property as nullable.

protected override async Task OnInitializedAsync()
{
GroupsAndPlaces = new List<Tuple<MpmGroup, int>>();
if (UserTask is null)
return;

Expand All @@ -85,32 +88,23 @@
GroupsList = groupResult.Value;
StateHasChanged();
}

foreach (var group in GroupsList)
{
var result = await UserDomain.GetUserPosition(group);
if (result.IsSuccess)
{
GroupsAndPlaces.Add(new Tuple<MpmGroup, int>(group, result.Value));
}
}

}

private void SwitchToGroups()
{
NavigationManager.NavigateTo("/groups");
}

public class TestGroups
{
public TestGroups() {}

public TestGroups(string name, int members, string description, int points, int position)
{
Name = name;
Members = members;
Description = description;
Points = points;
Position = position;
}

public string Name { get; set; }
public int Members { get; set; }
public string Description { get; set; }
public int Points { get; set; }
public int Position { get; set; }
}



Expand Down
206 changes: 112 additions & 94 deletions MPM-Betting.Blazor.ComponentLibrary/DesktopView/Matches.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@using MPM_Betting.DataModel.User
@using MPM_Betting.Services.Data
@using MPM_Betting.Services.Domains
@using Blazorise.LoadingIndicator

Check warning on line 14 in MPM-Betting.Blazor.ComponentLibrary/DesktopView/Matches.razor

View workflow job for this annotation

GitHub Actions / qodana

Redundant using directive

Using directive is not required by the code and can be safely removed
@using Blazorise
@using MudBlazor
@inject FootballApi Api
@inject NavigationManager NavigationManager
Expand All @@ -21,86 +23,90 @@
@attribute [Authorize]
@rendermode InteractiveServer

<div class="Blocker @(LoadingVisible ? "BlockerVisible" : "")">
<div class="loader"></div>
<h2>Placing bet...</h2>
</div>

@if (SelectedTeams != null && !expiredMatch)
{
<Modal @ref="ModalRef" Class="ModalSettings">
<ModalContent Centered>
<ModalHeader Background="Background.Dark">
<ModalTitle TextColor="TextColor.Default">Enter a new Bet</ModalTitle>
<CloseButton TextColor="TextColor.White"/>
</ModalHeader>
<ModalBody Background="Background.Dark" Class="ModalSettings">
<Field>
<h4 class="fw-bold">@SelectedTeams.Item1.Item1.Name.ToString() vs @SelectedTeams.Item1.Item2.Name.ToString()</h4>
</Field>
<Divider></Divider>
<Field>
<div class="ModalTeamEntries ModalEntries" >
<span>Home Win</span>
<span>Draw</span>
<span>Away Win</span>
</div>
<div class="ModalBetEntries ModalEntries">
<span class="BetEntry @(ChosenTeam == BetType.HomeWin ? "ModalActiveBet" : "")" onclick="@(() => SetChosenTeam(BetType.HomeWin) )">x @SelectedTeams.Item2.HomeWinPayOut</span>
<span class="BetEntry @(ChosenTeam == BetType.Draw ? "ModalActiveBet" : "")" onclick="@(() => SetChosenTeam(BetType.Draw))">x @SelectedTeams.Item2.DrawPayOut</span>
<span class="BetEntry @(ChosenTeam == BetType.AwayWin ? "ModalActiveBet" : "")" onclick="@(() => SetChosenTeam(BetType.AwayWin))">x @SelectedTeams.Item2.AwayWinPayOut</span>
<Modal @ref="ModalRef" Class="ModalSettings">
<ModalContent Centered>
<ModalHeader Background="Background.Dark">
<ModalTitle TextColor="TextColor.Default">Enter a new Bet</ModalTitle>
<CloseButton TextColor="TextColor.White"/>
</ModalHeader>
<ModalBody Background="Background.Dark" Class="ModalSettings">
<Field>
<h4 class="fw-bold">@SelectedTeams.Item1.Item1.Name.ToString() vs @SelectedTeams.Item1.Item2.Name.ToString()</h4>
</Field>
<Divider></Divider>
<Field>
<div class="ModalTeamEntries ModalEntries" >
<span>Home Win</span>
<span>Draw</span>
<span>Away Win</span>
</div>
<div class="ModalBetEntries ModalEntries">
<span class="BetEntry @(ChosenTeam == BetType.HomeWin ? "ModalActiveBet" : "")" onclick="@(() => SetChosenTeam(BetType.HomeWin) )">x @SelectedTeams.Item2.HomeWinPayOut</span>
<span class="BetEntry @(ChosenTeam == BetType.Draw ? "ModalActiveBet" : "")" onclick="@(() => SetChosenTeam(BetType.Draw))">x @SelectedTeams.Item2.DrawPayOut</span>
<span class="BetEntry @(ChosenTeam == BetType.AwayWin ? "ModalActiveBet" : "")" onclick="@(() => SetChosenTeam(BetType.AwayWin))">x @SelectedTeams.Item2.AwayWinPayOut</span>
</div>
</Field>
<Field>
<FieldLabel>Score Predition</FieldLabel>
<div class="mb-5">Getting this right double your win!</div>

<Validation UsePattern>
<div class="row ModalScoreEntryNames">
<div class="col-1"></div>
<div class="col-6">
<div>@SelectedTeams.Item1.Item1.Name</div>
</div>
<div class="col-4">
<div>@SelectedTeams.Item1.Item2.Name</div>
</div>
<div class="col-1"></div>
</div>
</Field>
<Field>
<FieldLabel>Score Predition</FieldLabel>
<div class="mb-5">Getting this right double your win!</div>

<Validation UsePattern>
<div class="row ModalScoreEntryNames">
<div class="col-1"></div>
<div class="col-6">
<div>@SelectedTeams.Item1.Item1.Name</div>
</div>
<div class="col-4">
<div>@SelectedTeams.Item1.Item2.Name</div>
</div>
<div class="col-1"></div>
<div class="row ModalScoreEntry">
<div class="col-1"></div>
<div class="col-4">
<TextEdit Text="@scoreBets.HomeScore" TextChanged="@OnHomeScoreChanges" Pattern="^[0-9]\d*$" Placeholder="HomeTeam"></TextEdit>
</div>
<div class="row ModalScoreEntry">
<div class="col-1"></div>
<div class="col-4">
<TextEdit Text="@scoreBets.HomeScore" TextChanged="@OnHomeScoreChanges" Pattern="^[0-9]\d*$" Placeholder="HomeTeam"></TextEdit>
</div>
<div class="col-2">
<div>:</div>
</div>
<div class="col-4">
<TextEdit Text="@scoreBets.AwayScore" TextChanged="@OnAwayScoreChanges" Pattern="^[0-9]\d*$" Placeholder="AwayTeam"></TextEdit>
</div>
<div class="col-1"></div>
<div class="col-2">
<div>:</div>
</div>
</Validation>
</Field>
<Field>
<FieldLabel>Amount of credits to bet:</FieldLabel>
<Validation UsePattern>
<TextEdit Text="@BetAmount" TextChanged="@OnTextChanges" Pattern="^[1-9][0-9]*$" Placeholder="Enter Credits">

</TextEdit>
</Validation>
</Field>
@if (ModalErrorMessage != null)
{
<Divider/>
<Field>
<div class="ModalError ErrorMessage">
<div>@ModalErrorMessage</div>
<div class="col-4">
<TextEdit Text="@scoreBets.AwayScore" TextChanged="@OnAwayScoreChanges" Pattern="^[0-9]\d*$" Placeholder="AwayTeam"></TextEdit>
</div>
<div class="col-1"></div>
</div>
</Field>
}
</ModalBody>
<ModalFooter Background="Background.Dark">
<Button Color="Blazorise.Color.Secondary" Clicked="@HideModal">Close</Button>
<Button Color="Blazorise.Color.Primary" Clicked="@PlaceBet">Place Bet</Button>
</ModalFooter>
</ModalContent>
</Modal>
</Validation>
</Field>
<Field>
<FieldLabel>Amount of credits to bet:</FieldLabel>
<Validation UsePattern>
<TextEdit Text="@BetAmount" TextChanged="@OnTextChanges" Pattern="^[1-9][0-9]*$" Placeholder="Enter Credits">

</TextEdit>
</Validation>
</Field>
@if (ModalErrorMessage != null)
{
<Divider/>
<Field>
<div class="ModalError ErrorMessage">
<div>@ModalErrorMessage</div>
</div>
</Field>
}
</ModalBody>
<ModalFooter Background="Background.Dark">
<Button Color="Blazorise.Color.Secondary" Clicked="@HideModal">Close</Button>
<Button Color="Blazorise.Color.Primary" Clicked="@PlaceBet">Place Bet</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
else if (expiredMatch)
{
Expand All @@ -123,24 +129,26 @@ else if (expiredMatch)
}
else
{
<Modal @ref="ModalRef" Class="ModalSettings">
<ModalContent Centered>
<ModalHeader Background="Background.Dark">
<ModalTitle>Error Loading</ModalTitle>
<CloseButton/>
</ModalHeader>
<ModalBody Background="Background.Dark" Class="ModalSettings">
<Field>
<FieldLabel>Either try again or refresh the page</FieldLabel>
</Field>
</ModalBody>
<ModalFooter Background="Background.Dark">
<Button Color="Blazorise.Color.Primary" Clicked="@HideModal">OK</Button>
</ModalFooter>
</ModalContent>
</Modal>
<Modal @ref="ModalRef" Class="ModalSettings">
<ModalContent Centered>
<ModalHeader Background="Background.Dark">
<ModalTitle>Error Loading</ModalTitle>
<CloseButton/>
</ModalHeader>
<ModalBody Background="Background.Dark" Class="ModalSettings">
<Field>
<FieldLabel>Either try again or refresh the page</FieldLabel>
</Field>
</ModalBody>
<ModalFooter Background="Background.Dark">
<Button Color="Blazorise.Color.Primary" Clicked="@HideModal">OK</Button>
</ModalFooter>
</ModalContent>
</Modal>
}



<div class="MatchesDate">
<MatchesDatePicker MatchesPage="this"/>
</div>
Expand Down Expand Up @@ -234,6 +242,8 @@ else
MpmUser? User;
MpmDbContext dbContext;

private bool LoadingVisible { get; set; }

private bool loaded;
private bool expiredMatch;

Expand Down Expand Up @@ -566,6 +576,8 @@ else
break;
}

UpdateLoading(true);


var result = await UserDomain.PlaceGameBet(quote, homeScore, awayScore, SelectedMatch.Id, int.Parse(BetAmount));

Expand All @@ -577,18 +589,26 @@ else
ModalErrorMessage = "Invalid bet parameters!";
else
ModalErrorMessage = $"Some error: {result.Exception.Message}";
UpdateLoading(false);
return;
}

//TODO AddBet

SelectedTeams = null;
SelectedMatch = default;
ModalErrorMessage = "";
NavigationManager.Refresh();
NavigationManager.Refresh(true);
UpdateLoading(false);
await HideModal();
}

private string ModalErrorMessage { get; set; }

void UpdateLoading(bool value)
{
LoadingVisible = value;
}


public enum BetType
{
Expand All @@ -597,6 +617,4 @@ else
Draw,
AwayWin
}


}
Loading

0 comments on commit 77bbd2b

Please sign in to comment.