generated from Integry/Template_NetMauiBlazorHybrid
130 lines
5.4 KiB
Plaintext
130 lines
5.4 KiB
Plaintext
@using CommunityToolkit.Mvvm.Messaging
|
||
@using salesbook.Shared.Core.Dto
|
||
@using salesbook.Shared.Core.Dto.Activity
|
||
@using salesbook.Shared.Core.Dto.PageState
|
||
@using salesbook.Shared.Core.Entity
|
||
@using salesbook.Shared.Core.Interface.System.Network
|
||
@using salesbook.Shared.Core.Messages.Activity.Copy
|
||
@using salesbook.Shared.Core.Messages.Activity.New
|
||
@using salesbook.Shared.Core.Messages.Contact
|
||
@using salesbook.Shared.Core.Messages.Notification.Loaded
|
||
@using salesbook.Shared.Core.Messages.Notification.NewPush
|
||
@inject IDialogService Dialog
|
||
@inject IMessenger Messenger
|
||
@inject CopyActivityService CopyActivityService
|
||
@inject NewPushNotificationService NewPushNotificationService
|
||
@inject NotificationState Notification
|
||
@inject INetworkService NetworkService
|
||
@inject NotificationsLoadedService NotificationsLoadedService
|
||
|
||
<div class="container animated-navbar @(IsVisible ? "show-nav" : "hide-nav") @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
|
||
<nav class="navbar @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
|
||
<div class="container-navbar">
|
||
<ul class="navbar-nav flex-row nav-justified align-items-center w-100 text-center">
|
||
<li class="nav-item">
|
||
<NavLink class="nav-link" href="Users" Match="NavLinkMatch.All">
|
||
<div class="d-flex flex-column">
|
||
<i class="ri-group-line"></i>
|
||
<span>Contatti</span>
|
||
</div>
|
||
</NavLink>
|
||
</li>
|
||
<li class="nav-item">
|
||
<NavLink class="nav-link" href="Calendar" Match="NavLinkMatch.All">
|
||
<div class="d-flex flex-column">
|
||
<i class="ri-calendar-todo-line"></i>
|
||
<span>Agenda</span>
|
||
</div>
|
||
</NavLink>
|
||
</li>
|
||
<li class="nav-item">
|
||
<MudBadge Content="Notification.Count" Visible="Notification.Count > 0" Color="Color.Error" Overlap="true">
|
||
<NavLink class="nav-link" href="Notifications" Match="NavLinkMatch.All">
|
||
<div class="d-flex flex-column">
|
||
<i class="ri-notification-4-line"></i>
|
||
<span>Notifiche</span>
|
||
</div>
|
||
</NavLink>
|
||
</MudBadge>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
|
||
@if (PlusVisible)
|
||
{
|
||
<MudMenu PopoverClass="custom_popover" AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomRight">
|
||
<ActivatorContent>
|
||
<MudFab Class="custom-plus-button" Color="Color.Surface" Size="Size.Medium" IconSize="Size.Medium" IconColor="Color.Primary" StartIcon="@Icons.Material.Filled.Add"/>
|
||
</ActivatorContent>
|
||
<ChildContent>
|
||
<MudMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="() => CreateUser()">Nuovo contatto</MudMenuItem>
|
||
<MudMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="() => CreateActivity()">Nuova attivit<69></MudMenuItem>
|
||
</ChildContent>
|
||
</MudMenu>
|
||
}
|
||
</nav>
|
||
</div>
|
||
|
||
@code
|
||
{
|
||
private bool IsVisible { get; set; } = true;
|
||
private bool PlusVisible { get; set; } = true;
|
||
|
||
protected override Task OnInitializedAsync()
|
||
{
|
||
InitMessage();
|
||
|
||
NavigationManager.LocationChanged += (_, args) =>
|
||
{
|
||
var location = args.Location.Remove(0, NavigationManager.BaseUri.Length);
|
||
|
||
var newIsVisible = new List<string> { "Calendar", "Users", "Notifications", "Commessa" }
|
||
.Contains(location);
|
||
|
||
var newPlusVisible = new List<string> { "Calendar", "Users", "Commessa" }
|
||
.Contains(location);
|
||
|
||
if (IsVisible == newIsVisible && PlusVisible == newPlusVisible) return;
|
||
|
||
IsVisible = newIsVisible;
|
||
PlusVisible = newPlusVisible;
|
||
StateHasChanged();
|
||
};
|
||
return Task.CompletedTask;
|
||
}
|
||
|
||
private Task CreateActivity() => CreateActivity(null);
|
||
|
||
private async Task CreateActivity(ActivityDTO? activity)
|
||
{
|
||
var result = await ModalHelpers.OpenActivityForm(Dialog, activity, null);
|
||
|
||
if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(StbActivity))
|
||
{
|
||
Messenger.Send(new NewActivityMessage(((StbActivity)result.Data).ActivityId));
|
||
}
|
||
}
|
||
|
||
private async Task CreateUser()
|
||
{
|
||
var result = await ModalHelpers.OpenUserForm(Dialog, null);
|
||
|
||
if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(CRMCreateContactResponseDTO))
|
||
{
|
||
Messenger.Send(new NewContactMessage((CRMCreateContactResponseDTO)result.Data));
|
||
}
|
||
}
|
||
|
||
private void NewNotificationReceived(WtbNotification notification)
|
||
{
|
||
Notification.ReceivedNotifications.Add(notification);
|
||
InvokeAsync(StateHasChanged);
|
||
}
|
||
|
||
private void InitMessage()
|
||
{
|
||
CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto);
|
||
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
|
||
NotificationsLoadedService.OnNotificationsLoaded += () => InvokeAsync(StateHasChanged);
|
||
}
|
||
} |