2024-10-28 00:35:32 +01:00
|
|
|
using Microsoft.AspNetCore.Components;
|
2025-03-03 00:56:32 +01:00
|
|
|
using Refit;
|
|
|
|
|
using WatchIt.DTO.Models.Controllers.Accounts.Account;
|
|
|
|
|
using WatchIt.Website.Clients;
|
2024-10-30 23:28:47 +01:00
|
|
|
using WatchIt.Website.Services.Authentication;
|
2024-10-28 00:35:32 +01:00
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
namespace WatchIt.Website.Components.Panels.Pages.UserPage;
|
2024-10-28 00:35:32 +01:00
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
public partial class HeaderPanel : Component
|
2024-10-28 00:35:32 +01:00
|
|
|
{
|
2024-10-30 23:28:47 +01:00
|
|
|
#region SERVICES
|
|
|
|
|
|
2025-03-03 00:56:32 +01:00
|
|
|
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
|
|
|
|
|
[Inject] private IAccountsClient AccountsClient { get; set; } = default!;
|
2024-10-30 23:28:47 +01:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PARAMETERS
|
|
|
|
|
|
2024-11-10 14:33:41 +01:00
|
|
|
[Parameter] public required AccountResponse Data { get; set; }
|
|
|
|
|
[Parameter] public required List<AccountResponse> Followers { get; set; }
|
|
|
|
|
[Parameter] public AccountResponse? LoggedUserData { get; set; }
|
|
|
|
|
[Parameter] public Action<bool>? FollowingChanged { get; set; }
|
2024-10-30 23:28:47 +01:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region FIELDS
|
|
|
|
|
|
2024-11-10 14:33:41 +01:00
|
|
|
private bool _followLoading;
|
|
|
|
|
|
2024-10-30 23:28:47 +01:00
|
|
|
#endregion
|
2024-11-10 14:33:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-30 23:28:47 +01:00
|
|
|
#region PRIVATE METHODS
|
|
|
|
|
|
2024-11-10 14:33:41 +01:00
|
|
|
private async Task Follow()
|
2024-10-30 23:28:47 +01:00
|
|
|
{
|
2025-03-03 00:56:32 +01:00
|
|
|
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
|
2024-11-10 14:33:41 +01:00
|
|
|
_followLoading = true;
|
2025-03-03 00:56:32 +01:00
|
|
|
IApiResponse response;
|
2024-11-10 14:33:41 +01:00
|
|
|
if (Followers.Any(x => x.Id == LoggedUserData!.Id))
|
|
|
|
|
{
|
2025-03-03 00:56:32 +01:00
|
|
|
response = await AccountsClient.DeleteAccountFollow(token, Data.Id);
|
|
|
|
|
if (response.IsSuccessful)
|
2024-11-10 14:33:41 +01:00
|
|
|
{
|
|
|
|
|
Followers.RemoveAll(x => x.Id == LoggedUserData!.Id);
|
|
|
|
|
FollowingChanged?.Invoke(false);
|
2025-03-03 00:56:32 +01:00
|
|
|
}
|
2024-11-10 14:33:41 +01:00
|
|
|
}
|
|
|
|
|
else
|
2024-10-30 23:28:47 +01:00
|
|
|
{
|
2025-03-03 00:56:32 +01:00
|
|
|
response = await AccountsClient.PostAccountFollow(token, Data.Id);
|
|
|
|
|
if (response.IsSuccessful)
|
2024-11-10 14:33:41 +01:00
|
|
|
{
|
|
|
|
|
Followers.Add(LoggedUserData);
|
|
|
|
|
FollowingChanged?.Invoke(true);
|
2025-03-03 00:56:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (response.IsSuccessful)
|
|
|
|
|
{
|
|
|
|
|
_followLoading = false;
|
2024-10-30 23:28:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-10-28 00:35:32 +01:00
|
|
|
}
|