108 lines
No EOL
3.2 KiB
Text
108 lines
No EOL
3.2 KiB
Text
@using Iceshrimp.Frontend.Core.Miscellaneous
|
|
@using Iceshrimp.Frontend.Core.Services
|
|
@using Iceshrimp.Shared.Schemas.Web
|
|
@inject ApiService Api;
|
|
@inject ILogger<NoteLikeDetails> Logger;
|
|
@inject NavigationManager Nav;
|
|
|
|
@if (State is State.Loaded)
|
|
{
|
|
<div class="renotes">
|
|
@foreach (var el in RenotedBy)
|
|
{
|
|
<div @onclick="() => OpenProfile(el.Username, el.Host)" class="detail-entry">
|
|
<UserAvatar User="@el"/>
|
|
<div class="name-section">
|
|
<div class="displayname"><UserDisplayName User="@el"/></div>
|
|
<div class="username">@@@el.Username@(el.Host != null ? $"@{el.Host}" : "")</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
@if (EndReached == false)
|
|
{
|
|
<ScrollEnd IntersectionChange="LoadMore" ManualLoad="LoadMore"/>
|
|
}
|
|
</div>
|
|
}
|
|
@if (State is State.Loading)
|
|
{
|
|
<span class="loading"><LoadingSpinner Scale="1.5" /></span>
|
|
}
|
|
@if (State is State.Error)
|
|
{
|
|
<span>Failed to load</span>
|
|
}
|
|
|
|
|
|
@code {
|
|
[Parameter, EditorRequired] public required string NoteId { get; set; }
|
|
private State State { get; set; }
|
|
private List<UserResponse> RenotedBy { get; set; } = [];
|
|
private PaginationData Pd { get; set; } = null!;
|
|
private bool EndReached { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var pq = new PaginationQuery { Limit = 20 };
|
|
var res = await Api.Notes.GetRenotesAsync(NoteId, pq);
|
|
if (res is null)
|
|
{
|
|
State = State.NotFound;
|
|
Logger.LogWarning($"Renotes for '{NoteId}' not found.");
|
|
return;
|
|
}
|
|
|
|
if (res.Links.Next is null) EndReached = true;
|
|
RenotedBy = res.Data;
|
|
Pd = res.Links;
|
|
State = State.Loaded;
|
|
}
|
|
catch (ApiException e)
|
|
{
|
|
Logger.LogError(e, "Failed to load likes");
|
|
State = State.Error;
|
|
}
|
|
}
|
|
|
|
private async Task<PaginationWrapper<List<UserResponse>>?> 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.GetRenotesAsync(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;
|
|
RenotedBy.AddRange(res.Data);
|
|
}
|
|
catch (ApiException e)
|
|
{
|
|
Logger.LogError(e, "Failed to load renotes");
|
|
}
|
|
}
|
|
|
|
private void OpenProfile(string username, string? host)
|
|
{
|
|
var path = $"@{username}";
|
|
if (host != null)
|
|
{
|
|
path += $"@{host}";
|
|
}
|
|
|
|
Nav.NavigateTo($"/{path}");
|
|
}
|
|
} |