@using LANCommander.Client.Models
@using Photino.Blazor.CustomWindow.Components
@inherits LayoutComponentBase
@inject ImportService ImportService
@inject ProfileService ProfileService
@inject IMessageService MessageService
@inject NavigationManager NavigationManager
@inject ModalService ModalService
@inject IJSRuntime JS
@if (Settings != null && Settings.Profile != null && ProfileService.IsAuthenticated())
{
}
@Body
@code {
Settings Settings = null;
public bool Importing = false;
public IMessageService Messages { get; set; }
public static MainLayout _MainLayout { get; set; }
protected override async Task OnInitializedAsync()
{
_MainLayout = this;
Settings = SettingService.GetSettings();
Messages = MessageService;
ImportService.OnImportComplete += () =>
{
MessageService.Success("Import Complete", 3);
};
}
async Task Logout()
{
await ProfileService.Logout();
NavigationManager.NavigateTo("/Authenticate");
}
async Task ChangeAlias()
{
var settings = SettingService.GetSettings();
var modalOptions = new ModalOptions()
{
Title = "Change Name",
Maximizable = false,
DefaultMaximized = false,
Closable = true,
Centered = true
};
var modalRef = ModalService.CreateModal(modalOptions, settings.Profile.Alias);
modalRef.OnOk = async (newName) =>
{
await ProfileService.ChangeAlias(newName);
Settings = SettingService.GetSettings();
await InvokeAsync(StateHasChanged);
};
}
async void Import()
{
if (!Importing)
{
await JS.InvokeVoidAsync("sendMessage", "import");
Importing = true;
StateHasChanged();
MessageService.Info("Import Started", 2.5);
}
}
[JSInvokable("ImportComplete")]
public static void ImportComplete()
{
_MainLayout.Messages.Success("Import Complete!");
_MainLayout.Importing = false;
_MainLayout.StateHasChanged();
_MainLayout.ImportService.ImportHasCompleted();
}
}