LANCommander/LANCommander.Launcher/UI/Components/ProfileButton.razor
Pat Hartl b281919ab7 Import media if missing, refactor application login
Media is now imported if its given an ID that doesn't exist in the database. This should almost never happen, but it's there if needed.

The login process for the launcher has been refactored to do some initialization steps on application start. This should include pulling down the profile avatar and validating connection on start.

Fixes #124
2024-10-06 17:11:35 -05:00

75 lines
No EOL
2 KiB
Text

@inject ProfileService ProfileService
@inject NavigationManager NavigationManager
@inject ModalService ModalService
<Dropdown>
<Overlay>
<Menu>
<MenuItem OnClick="ChangeAlias" Disabled="Settings.Authentication.OfflineMode">
Change Name
</MenuItem>
<MenuItem OnClick="@(() => NavigationManager.NavigateTo("/Settings"))">
Settings
</MenuItem>
@if (!Settings.Authentication.OfflineMode)
{
<MenuItem OnClick="Logout">
Logout
</MenuItem>
}
</Menu>
</Overlay>
<ChildContent>
<Button Type="@ButtonType.Primary" Class="appbar-profile-button">
@if (Settings.Profile.AvatarId != null && Settings.Profile.AvatarId != Guid.Empty)
{
<MediaImage Id="@Settings.Profile.AvatarId" />
}
<span>@Settings.Profile.Alias</span>
</Button>
</ChildContent>
</Dropdown>
@code {
Models.Settings Settings = null;
protected override async Task OnInitializedAsync()
{
Settings = SettingService.GetSettings();
}
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 Task Logout()
{
await ProfileService.Logout();
NavigationManager.NavigateTo("/Authenticate");
}
}