@using Iceshrimp.Frontend.Core.Miscellaneous @using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Shared.Schemas.Web @inject ApiService Api; @inject ILogger Logger; @inject NavigationManager Nav; @if (State is State.Loaded) {
@foreach (var el in LikedBy) {
@@@el.Username@(el.Host != null ? $"@{el.Host}" : "")
} @if (EndReached == false) { }
} @if (State is State.Loading) { } @if (State is State.Error) { Failed to load } @code { [Parameter, EditorRequired] public required string NoteId { get; set; } private State State { get; set; } private List LikedBy { get; set; } = []; private PaginationData Pd { get; set; } = null!; private bool EndReached { get; set; } = false; protected override async Task OnInitializedAsync() { try { var pq = new PaginationQuery { Limit = 20 }; var res = await Api.Notes.GetNoteLikesAsync(NoteId, pq); if (res is null) { State = State.NotFound; Logger.LogWarning($"Likes for '{NoteId}' not found."); return; } if (res.Links.Next is null) EndReached = true; LikedBy = res.Data; State = State.Loaded; } catch (ApiException e) { Logger.LogError(e, "Failed to load likes"); State = State.Error; } } private async Task>?> FetchMore(PaginationData data) { if (data.Next is null) return null; var pq = new PaginationQuery { MaxId = data.Next?.Split('=')[1], Limit = 20 }; var res = await Api.Notes.GetNoteLikesAsync(NoteId, pq); return res; } private async Task LoadMore() { if (EndReached) return; try { var res = await FetchMore(Pd); if (res is null) { EndReached = true; return; } Pd = res.Links; LikedBy.AddRange(res.Data); } catch (ApiException e) { Logger.LogError(e, $"Failed to load likes"); } } private void OpenProfile(string username, string? host) { var path = $"@{username}"; if (host != null) { path += $"@{host}"; } Nav.NavigateTo($"/{path}"); } }