@page "/directory" @using System.Text.RegularExpressions @using System.Globalization @implements IDisposable @inject IJSRuntime JS @inject State State Welcome to the omg.lol member directory! Everyone here is awesome. @if (groupedAddresses != null) { IdnMapping idn = new IdnMapping();
@foreach(var group in groupedAddresses) {

— @group.Key —

}
} else { } @code { private List? addresses; private IOrderedEnumerable>? groupedAddresses; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); if (addresses == null || addresses.Count == 0){ addresses = await State.GetDirectory(); GroupAddresses(); } State.PropertyChanged += StateChanged; State.CanRefresh = true; await InvokeAsync(StateHasChanged); } private async void StateChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(State.IsRefreshing) && State.IsRefreshing) { using (State.GetRefreshToken()) { addresses = await State.GetDirectory(true); GroupAddresses(); await InvokeAsync(StateHasChanged); } } } private void GroupAddresses() { groupedAddresses = addresses?.GroupBy(s => { if (Regex.IsMatch(s, "^[0-9]", RegexOptions.IgnoreCase)) return "#"; else if (Regex.IsMatch(s, "^[a-z]", RegexOptions.IgnoreCase)) return s.First().ToString().ToUpper(); else return "😀"; }).OrderBy(g => g.Key); } public void Dispose() { State.PropertyChanged -= StateChanged; State.CanRefresh = false; } }