165 lines
5.8 KiB
Plaintext
165 lines
5.8 KiB
Plaintext
@inherits LocalizableComponentBase
|
|||
|
|
|
||
|
|
@* The staff's picks (/clientapi/admin/staff-picks): the accounts suggested first to every persona, in their order, a
|
||
|
|
persona here or a person elsewhere, found among the accounts this server knows (/api/v2/search, never resolving).
|
||
|
|
PrivaPub keeps 40 at most and refuses an account picked already (409) or one it can't suggest (404: a community, a
|
||
|
|
server's actor, a suspended or deleted account). One deleted, suspended or silenced since stays listed, suggested to
|
||
|
|
nobody. A pick is removed at once: it can be picked again. Every change is in the staff's log. *@
|
||
|
|
<div class="flex flex-col gap-4 w-full" data-staff-picks>
|
||
|
|
@if (IsLoading)
|
||
|
|
{
|
||
|
|
<p class="flex w-full items-center justify-center gap-2">
|
||
|
|
<DLoading Variant="DLoadingVariant.Dots" LabelText="@Localizer["loading"]" />
|
||
|
|
@Localizer["loading"]
|
||
|
|
</p>
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
<p class="text-xs opacity-70">@Localizer["Suggested first to every persona of this server, in this order, under Explore's Who to follow."]</p>
|
||
|
|
|
||
|
|
@if (picks.Count == 0)
|
||
|
|
{
|
||
|
|
<p class="text-sm opacity-70" data-staff-picks-empty>@Localizer["No account is picked yet."]</p>
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
<ul class="flex flex-col gap-2">
|
||
|
|
@foreach (var pick in picks)
|
||
|
|
{
|
||
|
|
<li class="flex flex-wrap items-center gap-2 pointer-coarse:gap-2 p-2 rounded-lg neo-raised neo-2xs @(pick.IsShown ? null : "opacity-60")"
|
||
|
|
data-staff-pick="@pick.Handle" data-staff-pick-id="@pick.AccountId" data-staff-pick-shown="@(pick.IsShown ? "true" : "false")">
|
||
|
|
<i class="@(pick.IsLocal ? "ion-md-person" : "ion-md-globe") text-lg" aria-hidden="true"></i>
|
||
|
|
<a class="flex flex-col min-w-0 flex-1" href="@($"account/{Uri.EscapeDataString(pick.AccountId)}")">
|
||
|
|
<b class="truncate">@(pick.Name ?? pick.Handle ?? pick.AccountId)</b>
|
||
|
|
<span class="text-xs opacity-70 truncate">@(pick.Handle is { Length: > 0 } handle ? "@" + handle : pick.AccountId)</span>
|
||
|
|
</a>
|
||
|
|
@if (!pick.IsShown)
|
||
|
|
{
|
||
|
|
<DBadge Size="DSize.Sm" Variant="DBadgeVariant.Soft" Color="DColor.Warning"
|
||
|
|
title="@Localizer["Deleted, suspended or silenced since it was picked: suggested to nobody."]">@Localizer["Not suggested now"]</DBadge>
|
||
|
|
}
|
||
|
|
<DButton Size="DSize.Sm" Disabled="@(IsDefaultDisabled || isActing)" OnClick="() => Remove(pick)" data-staff-pick-remove>
|
||
|
|
<i class="ion-md-close" aria-hidden="true"></i><span>@Localizer["Remove"]</span>
|
||
|
|
</DButton>
|
||
|
|
</li>
|
||
|
|
}
|
||
|
|
</ul>
|
||
|
|
}
|
||
|
|
|
||
|
|
<div class="flex flex-col gap-2">
|
||
|
|
<div class="flex flex-wrap items-center gap-2">
|
||
|
|
<DInput TValue="string" class="flex-1 min-w-48" Value="query" ValueChanged="Search" ValueExpression="() => query" Immediate="true"
|
||
|
|
autocomplete="off" placeholder="@Localizer["Search accounts here and elsewhere"]" aria-label="@Localizer["Search accounts here and elsewhere"]"
|
||
|
|
disabled="@IsFull" data-staff-pick-search>
|
||
|
|
<Prefix><i class="ion-md-search" aria-hidden="true"></i></Prefix>
|
||
|
|
</DInput>
|
||
|
|
<span class="text-xs opacity-70 tabular-nums" data-staff-picks-count>@picks.Count/@MaxPicks</span>
|
||
|
|
</div>
|
||
|
|
@if (query is { Length: > 0 })
|
||
|
|
{
|
||
|
|
<div class="flex flex-wrap gap-2 pointer-coarse:gap-2" data-staff-pick-options>
|
||
|
|
@foreach (var account in matches)
|
||
|
|
{
|
||
|
|
<DButton Size="DSize.Sm" class="max-w-full" Disabled="@(IsDefaultDisabled || isActing || IsFull)" OnClick="() => Add(account)"
|
||
|
|
data-staff-pick-option="@account.Id">
|
||
|
|
<i class="ion-md-add" aria-hidden="true"></i>
|
||
|
|
<span class="truncate">@account.Name</span><span class="text-xs opacity-70 truncate">@("@" + account.Acct)</span>
|
||
|
|
</DButton>
|
||
|
|
}
|
||
|
|
@if (matches.Count == 0 && !isSearching)
|
||
|
|
{
|
||
|
|
<span class="text-xs opacity-70">@Localizer["No account matches."]</span>
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
[Inject] InstanceAdminService InstanceAdminService { get; set; }
|
||
|
|
[Inject] AccountService AccountService { get; set; }
|
||
|
|
|
||
|
|
/// <summary>PrivaPub's limit (InstanceAdminController.MaxStaffPicks).</summary>
|
||
|
|
const int MaxPicks = 40;
|
||
|
|
|
||
|
|
List<ViewStaffPick> picks = [];
|
||
|
|
string query;
|
||
|
|
List<Account> matches = [];
|
||
|
|
int searching;
|
||
|
|
bool isSearching;
|
||
|
|
bool isActing;
|
||
|
|
|
||
|
|
bool IsFull => picks.Count >= MaxPicks;
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync()
|
||
|
|
{
|
||
|
|
if (CascadingState.IsOffline)
|
||
|
|
{
|
||
|
|
WhenOnline(LoadData);
|
||
|
|
StartOnlinePolling();
|
||
|
|
IsLoading = false;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
await LoadData();
|
||
|
|
IsLoading = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
async Task LoadData() => picks = await InstanceAdminService.StaffPicks();
|
||
|
|
|
||
|
|
async Task Search(string typed)
|
||
|
|
{
|
||
|
|
query = typed;
|
||
|
|
var lookup = ++searching;
|
||
|
|
if (string.IsNullOrWhiteSpace(typed))
|
||
|
|
{
|
||
|
|
matches = [];
|
||
|
|
isSearching = false;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
isSearching = true;
|
||
|
|
await Task.Delay(300);
|
||
|
|
if (lookup != searching)
|
||
|
|
return;
|
||
|
|
var found = await AccountService.Suggest(typed.Trim(), false);
|
||
|
|
if (lookup != searching)
|
||
|
|
return;
|
||
|
|
// people only (PrivaPub takes no community), and none picked already
|
||
|
|
matches = [.. found.Accounts.Where(a => !a.Group && picks.All(p => p.AccountId != a.Id))];
|
||
|
|
isSearching = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
async Task Add(Account account)
|
||
|
|
{
|
||
|
|
isActing = true;
|
||
|
|
var result = await InstanceAdminService.AddStaffPick(account.Id);
|
||
|
|
isActing = false;
|
||
|
|
if (result.IsInvalid)
|
||
|
|
{
|
||
|
|
Toast.AddResponseError(result);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
picks = (List<ViewStaffPick>)result.Data;
|
||
|
|
query = null;
|
||
|
|
matches = [];
|
||
|
|
Toast.AddResponseSuccess(Localizer["{0} is suggested to every persona.", account.Name]);
|
||
|
|
}
|
||
|
|
|
||
|
|
async Task Remove(ViewStaffPick pick)
|
||
|
|
{
|
||
|
|
isActing = true;
|
||
|
|
var result = await InstanceAdminService.RemoveStaffPick(pick.AccountId);
|
||
|
|
isActing = false;
|
||
|
|
if (result.IsInvalid)
|
||
|
|
{
|
||
|
|
Toast.AddResponseError(result);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
picks = (List<ViewStaffPick>)result.Data;
|
||
|
|
Toast.AddResponseSuccess(Localizer["{0} is no longer suggested by the staff.", pick.Name ?? pick.Handle ?? pick.AccountId]);
|
||
|
|
}
|
||
|
|
}
|