LANCommander/LANCommander.Client/UI/MainLayout.razor

119 lines
No EOL
3.2 KiB
Text

@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
<CustomWindow HeaderHeight="37">
<HeaderExtraControlsLayout>
<Space Direction="@DirectionVHType.Horizontal">
<SpaceItem>
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Sync" OnClick="Import" Loading="@Importing" />
</SpaceItem>
@if (Settings != null && Settings.Profile != null && ProfileService.IsAuthenticated())
{
<SpaceItem>
<Dropdown>
<Overlay>
<Menu>
<MenuItem OnClick="Logout">
Logout
</MenuItem>
<MenuItem OnClick="ChangeAlias">
Change Name
</MenuItem>
</Menu>
</Overlay>
<ChildContent>
<Button Type="@ButtonType.Primary" Class="appbar-profile-button">
<img src="data:image/png;base64,@(Settings.Profile.Avatar)" />
@Settings.Profile.Alias
</Button>
</ChildContent>
</Dropdown>
</SpaceItem>
}
</Space>
</HeaderExtraControlsLayout>
<WindowContent>
<Layout>
<Content>
@Body
</Content>
</Layout>
<LANCommander.Client.UI.Components.Footer />
<AntContainer />
<RedirectToLogin />
</WindowContent>
</CustomWindow>
@code {
Settings Settings = null;
bool Importing = false;
protected override async Task OnInitializedAsync()
{
Settings = SettingService.GetSettings();
}
async Task Logout()
{
await ProfileService.Logout();
NavigationManager.NavigateTo("/Authenticate", true);
}
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<ChangeAliasDialog, string, string>(modalOptions, settings.Profile.Alias);
modalRef.OnOk = async (newName) =>
{
await ProfileService.ChangeAlias(newName);
Settings = SettingService.GetSettings();
await InvokeAsync(StateHasChanged);
};
}
async void Import()
{
var config = new MessageConfig()
{
Content = "Importing...",
Duration = 0
};
Importing = true;
var task = MessageService.Loading(config);
await ImportService.ImportAsync();
task.Start();
Importing = true;
}
}