[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.Assets.PhosphorIcons
@using Iceshrimp.Frontend.Core.Miscellaneous
@using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Frontend.Localization @using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web @using Iceshrimp.Shared.Schemas.Web
@using Microsoft.Extensions.Localization @using Microsoft.Extensions.Localization
@inject IStringLocalizer<Localization> Loc; @inject IStringLocalizer<Localization> Loc;
@inject ApiService Api; @inject ApiService Api;
@inject GlobalComponentSvc Global;
@if (_buttonType == ButtonType.Self) return; @if (_buttonType == ButtonType.Self) return;
<span class="follow-button"> <span class="follow-button">
@ -34,6 +36,12 @@
<Icon Name="Icons.X" class="icon"/> <Icon Name="Icons.X" class="icon"/>
</button> </button>
break; break;
case ButtonType.Blocking:
<button @onclick="Action" class="btn">
<span class="text">@Loc["Unblock"]</span>
<Icon Name="Icons.Prohibit" class="icon"/>
</button>
break;
} }
</span> </span>
@ -54,10 +62,13 @@
FollowBack, FollowBack,
FollowLocked, FollowLocked,
CancelRequest, CancelRequest,
Blocking,
Self Self
} }
private async Task Action() private async Task Action()
{
try
{ {
switch (_buttonType) switch (_buttonType)
{ {
@ -68,6 +79,14 @@
case ButtonType.Unfollow or ButtonType.CancelRequest: case ButtonType.Unfollow or ButtonType.CancelRequest:
await Unfollow(); await Unfollow();
break; 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(); StateHasChanged();
} }
private async Task Unblock()
{
await Api.Users.UnblockUserAsync(User.Id);
UserProfile.Relations -= (int)Relations.Blocking;
ChooseButton();
StateHasChanged();
}
private void ChooseButton() private void ChooseButton()
{ {
if (UserProfile.Relations == Relations.None) if (UserProfile.Relations == Relations.None)
@ -112,6 +139,11 @@
_buttonType = ButtonType.CancelRequest; _buttonType = ButtonType.CancelRequest;
} }
if (UserProfile.Relations.HasFlag(Relations.Blocking))
{
_buttonType = ButtonType.Blocking;
}
if (UserProfile.Relations.HasFlag(Relations.Self)) if (UserProfile.Relations.HasFlag(Relations.Self))
{ {
_buttonType = ButtonType.Self; _buttonType = ButtonType.Self;