Iceshrimp.NET/Iceshrimp.Frontend/Components/FollowRequestEntry.razor
2024-09-13 21:44:31 +02:00

58 lines
No EOL
2 KiB
Text

@using Iceshrimp.Assets.PhosphorIcons
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<Localization> Loc;
@inject ApiService Api;
@inject NavigationManager NavigationManager;
<div class="follow-request-card">
<UserProfileCard User="FollowRequest.User" ShowBio="false"></UserProfileCard>
<div class="buttons">
@if (_followBack)
{
<button @onclick="AcceptAndFollowBack" class="btn accept">
<Icon Name="Icons.ArrowsLeftRight"/>
</button>
}
<button @onclick="Accept" class="btn accept">
<Icon Name="Icons.Check"/>
</button>
<button @onclick="Reject" class="btn decline">
<Icon Name="Icons.X"/>
</button>
</div>
</div>
@code {
[Parameter] [EditorRequired] public required FollowRequestResponse FollowRequest { get; set; }
[Parameter] [EditorRequired] public required EventCallback<string> OnDelete { get; set; }
private bool _followBack = false;
protected override async Task OnInitializedAsync()
{
var profile = await Api.Users.GetUserProfile(FollowRequest.User.Id);
if (profile != null) _followBack = profile.Relations.HasFlag(Relations.None);
}
private async void Accept()
{
await Api.FollowRequests.AcceptFollowRequest(FollowRequest.Id);
await OnDelete.InvokeAsync(FollowRequest.Id);
}
private async void AcceptAndFollowBack()
{
await Api.FollowRequests.AcceptFollowRequest(FollowRequest.Id);
await Api.Users.FollowUser(FollowRequest.User.Id);
await OnDelete.InvokeAsync(FollowRequest.Id);
}
private async void Reject()
{
await Api.FollowRequests.RejectFollowRequest(FollowRequest.Id);
await OnDelete.InvokeAsync(FollowRequest.Id);
}
}