76 lines
2.6 KiB
Plaintext
76 lines
2.6 KiB
Plaintext
@inject IUserSessionService Session
|
|
@inject SharepointToolbox.Web.Infrastructure.Persistence.ProfileRepository ProfileRepo
|
|
@implements IDisposable
|
|
@using SharepointToolbox.Web.Core.Models
|
|
@using SharepointToolbox.Web.Services.Session
|
|
|
|
<div class="profile-selector">
|
|
<button class="profile-selector-trigger @(Session.HasProfile ? "" : "unset")" @onclick="ToggleAsync">
|
|
<span class="profile-selector-icon">🏢</span>
|
|
<span class="profile-selector-name">@(Session.CurrentProfile?.Name ?? "Select a profile")</span>
|
|
<span class="profile-selector-caret @(_open ? "open" : "")">▾</span>
|
|
</button>
|
|
|
|
@if (_open)
|
|
{
|
|
<div class="profile-selector-backdrop" @onclick="Close"></div>
|
|
<div class="profile-selector-menu">
|
|
@if (_profiles.Count == 0)
|
|
{
|
|
<div class="profile-selector-empty">No profiles configured.</div>
|
|
}
|
|
else
|
|
{
|
|
@foreach (var p in _profiles)
|
|
{
|
|
var active = Session.CurrentProfile?.Id == p.Id;
|
|
<button class="profile-selector-item @(active ? "active" : "")" @onclick="() => Select(p)">
|
|
<span class="profile-selector-item-text">
|
|
<span class="profile-selector-item-name">@p.Name</span>
|
|
<span class="profile-selector-item-url">@p.TenantUrl</span>
|
|
</span>
|
|
@if (active)
|
|
{
|
|
<span class="profile-selector-check">✓</span>
|
|
}
|
|
</button>
|
|
}
|
|
}
|
|
<a class="profile-selector-manage" href="/profiles" @onclick="Close">⚙️ Manage profiles</a>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@code {
|
|
private bool _open;
|
|
private List<TenantProfile> _profiles = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Session.ProfileChanged += OnProfileChanged;
|
|
await LoadProfilesAsync();
|
|
}
|
|
|
|
private void OnProfileChanged() => InvokeAsync(StateHasChanged);
|
|
|
|
private async Task LoadProfilesAsync()
|
|
=> _profiles = (await ProfileRepo.LoadAsync()).ToList();
|
|
|
|
private async Task ToggleAsync()
|
|
{
|
|
_open = !_open;
|
|
// Refresh the list when opening so newly created/edited profiles show up without a reload.
|
|
if (_open) await LoadProfilesAsync();
|
|
}
|
|
|
|
private void Close() => _open = false;
|
|
|
|
private void Select(TenantProfile p)
|
|
{
|
|
_open = false;
|
|
Session.SetProfile(p);
|
|
}
|
|
|
|
public void Dispose() => Session.ProfileChanged -= OnProfileChanged;
|
|
}
|