[frontend/components] Add blocking state to FollowButton

This commit is contained in:
pancakes 2025-02-23 15:54:09 +10:00 committed by Laura Hausmann
parent f16836ca31
commit 17bfc5ff54
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -1,10 +1,12 @@
@using Iceshrimp.Assets.PhosphorIcons
@using Iceshrimp.Frontend.Core.Miscellaneous
@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 GlobalComponentSvc Global;
@if (_buttonType == ButtonType.Self) return;
<span class="follow-button">
@ -34,6 +36,12 @@
<Icon Name="Icons.X" class="icon"/>
</button>
break;
case ButtonType.Blocking:
<button @onclick="Action" class="btn">
<span class="text">@Loc["Unblock"]</span>
<Icon Name="Icons.Prohibit" class="icon"/>
</button>
break;
}
</span>
@ -54,10 +62,13 @@
FollowBack,
FollowLocked,
CancelRequest,
Blocking,
Self
}
private async Task Action()
{
try
{
switch (_buttonType)
{
@ -68,6 +79,14 @@
case ButtonType.Unfollow or ButtonType.CancelRequest:
await Unfollow();
break;
case ButtonType.Blocking:
await Unblock();
break;
}
}
catch (ApiException e)
{
await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
}
}
@ -90,6 +109,14 @@
StateHasChanged();
}
private async Task Unblock()
{
await Api.Users.UnblockUserAsync(User.Id);
UserProfile.Relations -= (int)Relations.Blocking;
ChooseButton();
StateHasChanged();
}
private void ChooseButton()
{
if (UserProfile.Relations == Relations.None)
@ -112,6 +139,11 @@
_buttonType = ButtonType.CancelRequest;
}
if (UserProfile.Relations.HasFlag(Relations.Blocking))
{
_buttonType = ButtonType.Blocking;
}
if (UserProfile.Relations.HasFlag(Relations.Self))
{
_buttonType = ButtonType.Self;