mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02: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.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using Radzen;
|
||||
using WotBlitzStatisticsPro.Blazor.Services;
|
||||
|
||||
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<DialogService>();
|
||||
builder.Services.AddScoped<ISearchDialogService, SearchDialogService>();
|
||||
|
||||
builder.Services.AddMediatR(typeof(Program));
|
||||
|
||||
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>
|
||||
<ChildContent>
|
||||
<div class="row justify-content-start align-items-center">
|
||||
<div class="col-6 d-flex align-items-center">
|
||||
<RadzenSidebarToggle Click="@(args => { sidebarExpanded = !sidebarExpanded; bodyExpanded = !bodyExpanded; })">
|
||||
<RadzenSidebarToggle Click="@(args => InvertSideBar())">
|
||||
</RadzenSidebarToggle>
|
||||
<RadzenLabel Text="WOT Blitz statistics">
|
||||
</RadzenLabel>
|
||||
@@ -15,7 +15,7 @@
|
||||
</ChildContent>
|
||||
</RadzenHeader>
|
||||
<div style="width:100%">
|
||||
<RadzenBody @ref="@body0" @bind-Expanded="@bodyExpanded">
|
||||
<RadzenBody @ref="@Body0" @bind-Expanded="@BodyExpanded">
|
||||
<ChildContent>
|
||||
<RadzenContentContainer Name="main">
|
||||
@Body
|
||||
@@ -23,41 +23,15 @@
|
||||
</ChildContent>
|
||||
</RadzenBody>
|
||||
</div>
|
||||
<RadzenSidebar @ref="@sidebar0" @bind-Expanded="@sidebarExpanded">
|
||||
<RadzenSidebar @ref="@Sidebar0" @bind-Expanded="@SidebarExpanded">
|
||||
<ChildContent>
|
||||
<NavMenu />
|
||||
<NavMenu CloseSideBar=@InvertSideBar/>
|
||||
</ChildContent>
|
||||
</RadzenSidebar>
|
||||
<RadzenFooter>
|
||||
<ChildContent>
|
||||
<RadzenLabel Text="WOT Blitz statistics, Copyright © 2021">
|
||||
</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>
|
||||
</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>
|
||||
<RadzenPanelMenu >
|
||||
<RadzenPanelMenuItem Text="Home" Icon="home" Path="/"></RadzenPanelMenuItem>
|
||||
<RadzenPanelMenuItem Text="Counter" Icon="add_circle" Path="counter"></RadzenPanelMenuItem>
|
||||
@inherits NavMenuBase
|
||||
<div>
|
||||
<RadzenPanelMenu Click="@(MenuClicked)">
|
||||
<RadzenPanelMenuItem Text="Home" Icon="home"></RadzenPanelMenuItem>
|
||||
<RadzenPanelMenuItem Text="Search player" Icon="person_search"></RadzenPanelMenuItem>
|
||||
<RadzenPanelMenuItem Text="Search clan" Icon="screen_search_desktop"></RadzenPanelMenuItem>
|
||||
</RadzenPanelMenu>
|
||||
</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>
|
||||
|
||||
<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.DevServer" Version="5.0.4" PrivateAssets="all" />
|
||||
<PackageReference Include="Radzen.Blazor" Version="3.2.0" />
|
||||
@@ -16,4 +18,8 @@
|
||||
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Messages\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.DataA
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Tests", "WotBlitzStatisticsPro.Tests\WotBlitzStatisticsPro.Tests.csproj", "{551C3088-C6EA-45E1-A665-7C924C8407EB}"
|
||||
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
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
Reference in new issue
Block a user