[frontend] Add "Accept and follow back" button

This commit is contained in:
pancakes 2024-07-31 01:05:08 +10:00 committed by Laura Hausmann
parent 10650c55b8
commit a169bbc1c6
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -11,6 +11,12 @@
<div class="follow-request-card"> <div class="follow-request-card">
<UserProfileCard User="FollowRequest.User" ShowBio="false"></UserProfileCard> <UserProfileCard User="FollowRequest.User" ShowBio="false"></UserProfileCard>
<div class="buttons"> <div class="buttons">
@if (_followBack)
{
<button @onclick="AcceptAndFollowBack" class="btn accept">
<Icon Name="Icons.ArrowsLeftRight"/>
</button>
}
<button @onclick="Accept" class="btn accept"> <button @onclick="Accept" class="btn accept">
<Icon Name="Icons.Check"/> <Icon Name="Icons.Check"/>
</button> </button>
@ -23,12 +29,27 @@
@code { @code {
[Parameter] [EditorRequired] public required FollowRequestResponse FollowRequest { get; set; } [Parameter] [EditorRequired] public required FollowRequestResponse FollowRequest { get; set; }
[Parameter] [EditorRequired] public required EventCallback<string> OnDelete { 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() private async void Accept()
{ {
await Api.FollowRequests.AcceptFollowRequest(FollowRequest.Id); await Api.FollowRequests.AcceptFollowRequest(FollowRequest.Id);
await OnDelete.InvokeAsync(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() private async void Reject()
{ {
await Api.FollowRequests.RejectFollowRequest(FollowRequest.Id); await Api.FollowRequests.RejectFollowRequest(FollowRequest.Id);