@inherits LocalizableComponentBase @* The accounts waiting for the persona to accept their follow (/api/v1/follow_requests), newest first, each opening its profile, accepted (authorize) or refused (reject) here; "Load more" follows the Link header's next page when PrivaPub sends one. On the persona's own profile (hidden while nobody waits) and in a sheet from the Notifications tab. *@ @if (!HideWhenEmpty || IsLoading || requests.Count > 0) {
@if (ShowHeading) {

@Localizer["Follow requests"]

} @if (IsLoading) {

@Localizer["loading"]

} else if (requests.Count == 0) {

@Localizer["No follow request is waiting."]

} @foreach (var account in requests) {
@* alt="": the name is next to it. *@ @CustomEmojis.Text(account.Name, account.Emojis) @("@" + account.Acct) @if (answers.TryGetValue(account.Id, out var accepted)) { @(accepted ? Localizer["Accepted."] : Localizer["Refused."]) } else {
@Localizer["Accept"] @Localizer["Refuse"]
}
} @if (maxId is not null) { @if (isLoadingMore) { } @Localizer["Load more"] }
} @code { [Inject] AccountService AccountService { get; set; } /// Renders nothing once read with nobody waiting (the persona's own profile). [Parameter] public bool HideWhenEmpty { get; set; } [Parameter] public bool ShowHeading { get; set; } /// A request was answered: true when accepted. [Parameter] public EventCallback OnAnswered { get; set; } List requests = []; // what was answered here, by account id: accepted (true) or refused Dictionary answers = new(); HashSet busy = []; string maxId; string loadedPersonaId; bool isLoadingMore; // The persona changed (NavMenu's switcher): its requests are another persona's. protected override async Task OnParametersSetAsync() { if (CascadingState.PersonaId == loadedPersonaId) return; loadedPersonaId = CascadingState.PersonaId; if (CascadingState.IsOffline) { WhenOnline(LoadData); StartOnlinePolling(); IsLoading = false; return; } await LoadData(); } async Task LoadData() { IsLoading = true; requests = []; answers = new(); maxId = null; await LoadPage(); IsLoading = false; } async Task LoadPage() { var result = await AccountService.FollowRequests(maxId); if (result.IsInvalid) { Toast.AddResponseError(result); return; } var page = (AccountPage)result.Data; var known = requests.Select(a => a.Id).ToHashSet(); requests.AddRange(page.Accounts.Where(a => known.Add(a.Id))); maxId = page.MaxId; } async Task LoadMore() { isLoadingMore = true; await LoadPage(); isLoadingMore = false; } async Task Answer(Account account, bool accept) { busy.Add(account.Id); var result = await AccountService.Answer(account.Id, accept); busy.Remove(account.Id); if (result.IsInvalid) { Toast.AddResponseError(result); return; } answers[account.Id] = accept; await OnAnswered.InvokeAsync(accept); } }