2024-06-18 07:11:28 +00:00
@page "/directory"
2024-06-20 04:25:48 +00:00
@using System.Text.RegularExpressions
@using System.Globalization
2024-06-18 07:11:28 +00:00
@implements IDisposable
@inject IJSRuntime JS
@inject State State
<RefreshButton></RefreshButton>
<PageHeading title="Address Directory" icon="fa-duotone fa-address-book">
<Description>Welcome to the <a href="https://home.omg.lol/directory">omg.lol member directory</a>! Everyone here is awesome. <i class="fa-solid fa-sparkles"></i></Description>
</PageHeading>
2024-06-20 04:25:48 +00:00
@if (groupedAddresses != null) {
IdnMapping idn = new IdnMapping();
<article id="directoryIndex" class="responsive">
<nav class="wrap">
@foreach (var group in groupedAddresses) {
2024-07-12 05:08:12 +00:00
<a @onclick='()=>{JS.InvokeVoidAsync("scrollToId", $"index-{group.Key}");}' class="button circle transparent honey">@group.Key</a>
2024-06-20 04:25:48 +00:00
}
</nav>
</article>
<article id="directory" class="responsive">
@foreach(var group in groupedAddresses) {
2024-07-12 05:08:12 +00:00
<h3 class="honey" id="index-@group.Key">— @group.Key —</h3>
2024-06-20 04:25:48 +00:00
<ul>
@foreach(string address in group) {
string displayAddress = address;
string linkAddress = address;
if (group.Key == "😀") {
try {
linkAddress = idn.GetAscii(address);
displayAddress = $"{address} {linkAddress}";
}
catch (Exception) { }
}
<li>
2024-07-25 05:00:46 +00:00
<a class="chip medium no-border tiny-margin transparent" href="/person/@address">
2024-06-20 04:25:48 +00:00
<img class="circle avatar responsive" src="https://profiles.cache.lol/@linkAddress/picture">
<span>@displayAddress</span>
</a>
</li>
}
</ul>
}
</article>
}
else {
2024-06-18 07:11:28 +00:00
<LoadingCard id="address-loading" icon="fa-duotone fa-address-book"></LoadingCard>
2024-06-20 04:25:48 +00:00
}
2024-06-18 07:11:28 +00:00
@code {
private List<string>? addresses;
2024-06-20 04:25:48 +00:00
private IOrderedEnumerable<IGrouping<string, string>>? groupedAddresses;
2024-06-18 07:11:28 +00:00
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
2024-06-20 04:25:48 +00:00
if (addresses == null || addresses.Count == 0){
addresses = await State.GetDirectory();
GroupAddresses();
}
2024-06-18 07:11:28 +00:00
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) {
2024-06-24 04:52:45 +00:00
using (State.GetRefreshToken()) {
addresses = await State.GetDirectory(true);
GroupAddresses();
await InvokeAsync(StateHasChanged);
}
2024-06-18 07:11:28 +00:00
}
}
2024-06-20 04:25:48 +00:00
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);
}
2024-06-18 07:11:28 +00:00
public void Dispose() {
State.PropertyChanged -= StateChanged;
State.CanRefresh = false;
}
}