[frontend/pages] Add block and unblock actions to profile page
This commit is contained in:
parent
158fe10696
commit
f16836ca31
2 changed files with 62 additions and 0 deletions
|
@ -27,6 +27,12 @@ internal class UserControllerModel(ApiClient api)
|
||||||
public Task BiteUserAsync(string id) =>
|
public Task BiteUserAsync(string id) =>
|
||||||
api.CallAsync(HttpMethod.Post, $"/users/{id}/bite");
|
api.CallAsync(HttpMethod.Post, $"/users/{id}/bite");
|
||||||
|
|
||||||
|
public Task BlockUserAsync(string id) =>
|
||||||
|
api.CallAsync(HttpMethod.Post, $"/users/{id}/block");
|
||||||
|
|
||||||
|
public Task UnblockUserAsync(string id) =>
|
||||||
|
api.CallAsync(HttpMethod.Post, $"/users/{id}/unblock");
|
||||||
|
|
||||||
public Task<bool> FollowUserAsync(string id) => api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/follow");
|
public Task<bool> FollowUserAsync(string id) => api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/follow");
|
||||||
|
|
||||||
public Task<UserResponse?> RefetchUserAsync(string id) =>
|
public Task<UserResponse?> RefetchUserAsync(string id) =>
|
||||||
|
|
|
@ -80,6 +80,18 @@
|
||||||
<Text>@Loc["Remove follower"]</Text>
|
<Text>@Loc["Remove follower"]</Text>
|
||||||
</MenuElement>
|
</MenuElement>
|
||||||
}
|
}
|
||||||
|
@if (Profile != null && Profile.Relations.HasFlag(Relations.Blocking))
|
||||||
|
{
|
||||||
|
<MenuElement Icon="Icons.Prohibit" OnSelect="Unblock">
|
||||||
|
<Text>@Loc["Unblock"]</Text>
|
||||||
|
</MenuElement>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MenuElement Icon="Icons.Prohibit" OnSelect="Block">
|
||||||
|
<Text>@Loc["Block"]</Text>
|
||||||
|
</MenuElement>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@if (UserResponse.Host != null && Profile?.Url != null)
|
@if (UserResponse.Host != null && Profile?.Url != null)
|
||||||
{
|
{
|
||||||
|
@ -259,6 +271,50 @@
|
||||||
private void RemoveFromFollowers() =>
|
private void RemoveFromFollowers() =>
|
||||||
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, RemoveFromFollowersAction), Loc["Remove {0} from followers?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Remove follower"]);
|
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, RemoveFromFollowersAction), Loc["Remove {0} from followers?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Remove follower"]);
|
||||||
|
|
||||||
|
private void Block() =>
|
||||||
|
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, BlockCallback), Loc["Block {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Block"]);
|
||||||
|
|
||||||
|
private async Task BlockCallback(bool confirm)
|
||||||
|
{
|
||||||
|
if (!confirm) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Api.Users.BlockUserAsync(UserResponse.Id);
|
||||||
|
|
||||||
|
await GlobalComponentSvc.NoticeDialog?.Display(Loc["Blocked {0}", UserResponse.DisplayName ?? UserResponse.Username])!;
|
||||||
|
|
||||||
|
Profile!.Relations += (int)Relations.Blocking;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
await GlobalComponentSvc.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Unblock() =>
|
||||||
|
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, UnblockCallback), Loc["Unblock {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Unblock"]);
|
||||||
|
|
||||||
|
private async Task UnblockCallback(bool confirm)
|
||||||
|
{
|
||||||
|
if (!confirm) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Api.Users.UnblockUserAsync(UserResponse.Id);
|
||||||
|
|
||||||
|
await GlobalComponentSvc.NoticeDialog?.Display(Loc["Unblocked {0}", UserResponse.DisplayName ?? UserResponse.Username])!;
|
||||||
|
|
||||||
|
Profile!.Relations -= (int)Relations.Blocking;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
await GlobalComponentSvc.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OpenOriginal()
|
private void OpenOriginal()
|
||||||
{
|
{
|
||||||
if (Profile?.Url != null)
|
if (Profile?.Url != null)
|
||||||
|
|
Loading…
Add table
Reference in a new issue