LANCommander/LANCommander.Launcher/UI/Components/ProfileButton.razor

92 lines
2.5 KiB
Text
Raw Permalink Normal View History

@using LANCommander.Launcher.Data.Models
@using LANCommander.Launcher.Models
@inject UserService UserService
@inject ProfileService ProfileService
@inject AuthenticationService AuthenticationService
@inject NavigationManager NavigationManager
@inject ModalService ModalService
<Dropdown>
<Overlay>
<Menu>
<MenuItem OnClick="ChangeAlias" Disabled="ConnectionState.OfflineModeEnabled">
Change Name
</MenuItem>
<MenuItem OnClick="@(() => NavigationManager.NavigateTo("/Settings"))">
Settings
</MenuItem>
@if (!ConnectionState.OfflineModeEnabled)
{
<MenuItem OnClick="Logout">
Logout
</MenuItem>
}
</Menu>
</Overlay>
<ChildContent>
2024-12-31 18:21:41 -06:00
<Button Type="ButtonType.Primary" Class="appbar-profile-button">
2025-01-25 15:22:25 -06:00
@if (AvatarId != Guid.Empty)
{
2025-01-25 15:22:25 -06:00
<MediaImage Id="AvatarId" />
}
2025-01-25 15:22:25 -06:00
<span>@Alias</span>
</Button>
</ChildContent>
</Dropdown>
@code {
[CascadingParameter] public ConnectionState ConnectionState { get; set; }
Models.Settings Settings = null;
User User;
2025-01-25 15:22:25 -06:00
Guid AvatarId = Guid.Empty;
string Alias = "Player";
protected override async Task OnInitializedAsync()
{
ProfileService.OnProfileDownloaded += async (sender, args) =>
{
User = await UserService.GetCurrentUser();
2025-01-25 15:22:25 -06:00
AvatarId = User?.Avatar?.Id ?? Guid.Empty;
Alias = String.IsNullOrWhiteSpace(User?.Alias) ? User?.UserName ?? "Player" : User.Alias;
};
await ProfileService.DownloadProfileInfoAsync();
}
async Task ChangeAlias()
{
var modalOptions = new ModalOptions()
{
Title = "Change Name",
Maximizable = false,
DefaultMaximized = false,
Closable = true,
Centered = true
};
var modalRef = ModalService.CreateModal<ChangeAliasDialog, string, string>(modalOptions, User.Alias);
modalRef.OnOk = async (newName) =>
{
await ProfileService.ChangeAlias(newName);
2025-01-25 02:58:10 -06:00
await ProfileService.DownloadProfileInfoAsync();
Settings = SettingService.GetSettings();
await InvokeAsync(StateHasChanged);
};
}
async Task Logout()
{
await AuthenticationService.Logout();
NavigationManager.NavigateTo("/Authenticate");
}
}