mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-25 03:10:07 +01:00
feat: implemented Mediator and added dialog service
This commit is contained in:
1 parent
ec977c490a
commit
38c631bc44
13 files changed
+188
-54
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
using MediatR;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Model;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Blazor.Messages
|
||||||
|
{
|
||||||
|
public class OpenSearchDialogMessage: INotification
|
||||||
|
{
|
||||||
|
public DialogType Type { get; }
|
||||||
|
|
||||||
|
public OpenSearchDialogMessage(DialogType type)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace WotBlitzStatisticsPro.Blazor.Model
|
||||||
|
{
|
||||||
|
public enum DialogType
|
||||||
|
{
|
||||||
|
FindPlayer,
|
||||||
|
FindClan
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
@page "/counter"
|
|
||||||
|
|
||||||
<h1>Counter</h1>
|
|
||||||
|
|
||||||
<p>Current count: @currentCount</p>
|
|
||||||
|
|
||||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private int currentCount = 0;
|
|
||||||
|
|
||||||
private void IncrementCount()
|
|
||||||
{
|
|
||||||
currentCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@using WotBlitzStatisticsPro.Blazor.Model
|
||||||
|
<h3>SearchDialog</h3>
|
||||||
|
@DialogType
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public DialogType DialogType { get; set; }
|
||||||
|
}
|
||||||
@@ -3,7 +3,9 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Services;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.Blazor
|
namespace WotBlitzStatisticsPro.Blazor
|
||||||
{
|
{
|
||||||
@@ -17,6 +19,9 @@ namespace WotBlitzStatisticsPro.Blazor
|
|||||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||||
|
|
||||||
builder.Services.AddScoped<DialogService>();
|
builder.Services.AddScoped<DialogService>();
|
||||||
|
builder.Services.AddScoped<ISearchDialogService, SearchDialogService>();
|
||||||
|
|
||||||
|
builder.Services.AddMediatR(typeof(Program));
|
||||||
|
|
||||||
await builder.Build().RunAsync();
|
await builder.Build().RunAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Model;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||||
|
{
|
||||||
|
public interface ISearchDialogService
|
||||||
|
{
|
||||||
|
Task OpenSearchDialog(DialogType type);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
|
using Radzen;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Model;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Pages;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||||
|
{
|
||||||
|
public class SearchDialogService: ISearchDialogService, INotificationHandler<OpenSearchDialogMessage>
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly DialogService _dialogService;
|
||||||
|
|
||||||
|
public SearchDialogService(DialogService dialogService)
|
||||||
|
{
|
||||||
|
_dialogService = dialogService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task OpenSearchDialog(DialogType type)
|
||||||
|
{
|
||||||
|
await _dialogService.OpenAsync<SearchDialog>($"Search",
|
||||||
|
new Dictionary<string, object>() { { "DialogType", type } },
|
||||||
|
new DialogOptions() { Width = "300px", Height = "530px" });
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(OpenSearchDialogMessage notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return OpenSearchDialog(notification.Type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
@inherits LayoutComponentBase
|
@inherits MainLayoutBase
|
||||||
|
|
||||||
<RadzenDialog />
|
<RadzenDialog />
|
||||||
|
|
||||||
<RadzenHeader>
|
<RadzenHeader>
|
||||||
<ChildContent>
|
<ChildContent>
|
||||||
<div class="row justify-content-start align-items-center">
|
<div class="row justify-content-start align-items-center">
|
||||||
<div class="col-6 d-flex align-items-center">
|
<div class="col-6 d-flex align-items-center">
|
||||||
<RadzenSidebarToggle Click="@(args => { sidebarExpanded = !sidebarExpanded; bodyExpanded = !bodyExpanded; })">
|
<RadzenSidebarToggle Click="@(args => InvertSideBar())">
|
||||||
</RadzenSidebarToggle>
|
</RadzenSidebarToggle>
|
||||||
<RadzenLabel Text="WOT Blitz statistics">
|
<RadzenLabel Text="WOT Blitz statistics">
|
||||||
</RadzenLabel>
|
</RadzenLabel>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
</ChildContent>
|
</ChildContent>
|
||||||
</RadzenHeader>
|
</RadzenHeader>
|
||||||
<div style="width:100%">
|
<div style="width:100%">
|
||||||
<RadzenBody @ref="@body0" @bind-Expanded="@bodyExpanded">
|
<RadzenBody @ref="@Body0" @bind-Expanded="@BodyExpanded">
|
||||||
<ChildContent>
|
<ChildContent>
|
||||||
<RadzenContentContainer Name="main">
|
<RadzenContentContainer Name="main">
|
||||||
@Body
|
@Body
|
||||||
@@ -23,41 +23,15 @@
|
|||||||
</ChildContent>
|
</ChildContent>
|
||||||
</RadzenBody>
|
</RadzenBody>
|
||||||
</div>
|
</div>
|
||||||
<RadzenSidebar @ref="@sidebar0" @bind-Expanded="@sidebarExpanded">
|
<RadzenSidebar @ref="@Sidebar0" @bind-Expanded="@SidebarExpanded">
|
||||||
<ChildContent>
|
<ChildContent>
|
||||||
<NavMenu />
|
<NavMenu CloseSideBar=@InvertSideBar/>
|
||||||
</ChildContent>
|
</ChildContent>
|
||||||
</RadzenSidebar>
|
</RadzenSidebar>
|
||||||
<RadzenFooter>
|
<RadzenFooter>
|
||||||
<ChildContent>
|
<ChildContent>
|
||||||
<RadzenLabel Text="WOT Blitz statistics, Copyright © 2021">
|
<RadzenLabel Text="WOT Blitz statistics, Copyright © 2021">
|
||||||
</RadzenLabel>
|
</RadzenLabel>
|
||||||
<RadzenLink Text="[source]" Path="https://github.com/DrMboga/WotBlitzStatisticsBlazor" Target="_blank" Style="margin-left:5px;vertical-align:bottom;" />
|
<RadzenLink Text="DrMboga" Path="https://github.com/DrMboga/WotBlitzStatisticsBlazor" Target="_blank" Style="margin-left:5px;vertical-align:bottom;" />
|
||||||
</ChildContent>
|
</ChildContent>
|
||||||
</RadzenFooter>
|
</RadzenFooter>
|
||||||
|
|
||||||
@code {
|
|
||||||
RadzenSidebar sidebar0;
|
|
||||||
RadzenBody body0;
|
|
||||||
bool sidebarExpanded = false;
|
|
||||||
bool bodyExpanded = true;
|
|
||||||
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
@*if (httpContextAccessor != null && httpContextAccessor.HttpContext != null &&
|
|
||||||
httpContextAccessor.HttpContext.Request != null && httpContextAccessor.HttpContext.Request.Headers.ContainsKey("User-Agent"))
|
|
||||||
{
|
|
||||||
var userAgent = httpContextAccessor.HttpContext.Request.Headers["User-Agent"].FirstOrDefault();
|
|
||||||
if (!string.IsNullOrEmpty(userAgent))
|
|
||||||
{
|
|
||||||
if (userAgent.Contains("iPhone") || userAgent.Contains("Android") || userAgent.Contains("Googlebot"))
|
|
||||||
{
|
|
||||||
sidebarExpanded = false;
|
|
||||||
bodyExpanded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*@
|
|
||||||
|
|
||||||
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Radzen;
|
||||||
|
using Radzen.Blazor;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Blazor.Shared
|
||||||
|
{
|
||||||
|
public class MainLayoutBase: LayoutComponentBase
|
||||||
|
{
|
||||||
|
[Inject]
|
||||||
|
private DialogService DialogService { get; set; }
|
||||||
|
|
||||||
|
public RadzenSidebar Sidebar0;
|
||||||
|
public RadzenBody Body0;
|
||||||
|
public bool SidebarExpanded { get; set; } = false;
|
||||||
|
public bool BodyExpanded { get; set; } = true;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
//if (httpContextAccessor != null && httpContextAccessor.HttpContext != null &&
|
||||||
|
// httpContextAccessor.HttpContext.Request != null && httpContextAccessor.HttpContext.Request.Headers.ContainsKey("User-Agent"))
|
||||||
|
//{
|
||||||
|
// var userAgent = httpContextAccessor.HttpContext.Request.Headers["User-Agent"].FirstOrDefault();
|
||||||
|
// if (!string.IsNullOrEmpty(userAgent))
|
||||||
|
// {
|
||||||
|
// if (userAgent.Contains("iPhone") || userAgent.Contains("Android") || userAgent.Contains("Googlebot"))
|
||||||
|
// {
|
||||||
|
// SidebarExpanded = false;
|
||||||
|
// BodyExpanded = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvertSideBar()
|
||||||
|
{
|
||||||
|
SidebarExpanded = !SidebarExpanded;
|
||||||
|
BodyExpanded = !BodyExpanded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
<div>
|
@inherits NavMenuBase
|
||||||
<RadzenPanelMenu >
|
<div>
|
||||||
<RadzenPanelMenuItem Text="Home" Icon="home" Path="/"></RadzenPanelMenuItem>
|
<RadzenPanelMenu Click="@(MenuClicked)">
|
||||||
<RadzenPanelMenuItem Text="Counter" Icon="add_circle" Path="counter"></RadzenPanelMenuItem>
|
<RadzenPanelMenuItem Text="Home" Icon="home"></RadzenPanelMenuItem>
|
||||||
|
<RadzenPanelMenuItem Text="Search player" Icon="person_search"></RadzenPanelMenuItem>
|
||||||
|
<RadzenPanelMenuItem Text="Search clan" Icon="screen_search_desktop"></RadzenPanelMenuItem>
|
||||||
</RadzenPanelMenu>
|
</RadzenPanelMenu>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Radzen;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Model;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Services;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Blazor.Shared
|
||||||
|
{
|
||||||
|
public class NavMenuBase: ComponentBase
|
||||||
|
{
|
||||||
|
[Inject]
|
||||||
|
public NavigationManager NavManager { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
public IMediator Mediator { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
public ISearchDialogService SearchDialogService { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback CloseSideBar { get; set; }
|
||||||
|
|
||||||
|
public async Task MenuClicked(MenuItemEventArgs menuItem)
|
||||||
|
{
|
||||||
|
await CloseSideBar.InvokeAsync();
|
||||||
|
switch (menuItem.Text)
|
||||||
|
{
|
||||||
|
case "Home":
|
||||||
|
NavManager.NavigateTo("/");
|
||||||
|
break;
|
||||||
|
case "Search player":
|
||||||
|
await Mediator.Publish(new OpenSearchDialogMessage(DialogType.FindPlayer));
|
||||||
|
//await SearchDialogService.OpenSearchDialog(DialogType.FindPlayer);
|
||||||
|
break;
|
||||||
|
case "Search clan":
|
||||||
|
await Mediator.Publish(new OpenSearchDialogMessage(DialogType.FindClan));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MediatR" Version="9.0.0" />
|
||||||
|
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.4" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.4" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.4" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.4" PrivateAssets="all" />
|
||||||
<PackageReference Include="Radzen.Blazor" Version="3.2.0" />
|
<PackageReference Include="Radzen.Blazor" Version="3.2.0" />
|
||||||
@@ -16,4 +18,8 @@
|
|||||||
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
|
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Messages\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.DataA
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Tests", "WotBlitzStatisticsPro.Tests\WotBlitzStatisticsPro.Tests.csproj", "{551C3088-C6EA-45E1-A665-7C924C8407EB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Tests", "WotBlitzStatisticsPro.Tests\WotBlitzStatisticsPro.Tests.csproj", "{551C3088-C6EA-45E1-A665-7C924C8407EB}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.Blazor", "WotBlitzStatisticsPro.Blazor\WotBlitzStatisticsPro.Blazor.csproj", "{3A27736F-B5DD-4310-A013-2BB65C975104}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Blazor", "WotBlitzStatisticsPro.Blazor\WotBlitzStatisticsPro.Blazor.csproj", "{3A27736F-B5DD-4310-A013-2BB65C975104}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
Reference in new issue
Block a user