UserPage created

This commit is contained in:
2024-10-28 00:35:32 +01:00
Unverified
parent b53f907310
commit 017b3ac185
28 changed files with 145 additions and 5 deletions

View File

@@ -20,6 +20,9 @@ public class AccountResponse : Account
#region CONSTRUCTORS
[JsonConstructor]
public AccountResponse() {}
[SetsRequiredMembers]
public AccountResponse(Database.Model.Account.Account account)
{

View File

@@ -10,7 +10,7 @@
<ProjectReference Include="..\..\..\WatchIt.Common\WatchIt.Common.Model\WatchIt.Common.Model.csproj" />
<ProjectReference Include="..\..\..\WatchIt.Common\WatchIt.Common.Services\WatchIt.Common.Services.HttpClient\WatchIt.Common.Services.HttpClient.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.Tokens\WatchIt.Website.Services.Tokens.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj" />
</ItemGroup>
</Project>

View File

@@ -8,7 +8,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\WatchIt.Common\WatchIt.Common.Model\WatchIt.Common.Model.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
using Microsoft.AspNetCore.Components;
namespace WatchIt.Website.Components.Pages.UserPage.Panels;
public partial class UserPageHeaderPanelComponent : ComponentBase
{
}

View File

@@ -61,8 +61,10 @@
</Button>
<DropdownToggle Color="Color.Default" Split />
<DropdownMenu >
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/user"))">Your profile</DropdownItem>
@if (_user.IsAdmin)
{
<DropdownDivider/>
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/admin"))">Administrator panel</DropdownItem>
}
<DropdownDivider/>

View File

@@ -1 +1,49 @@
@page "/user/{id:long}"
@using System.Text
@using WatchIt.Website.Components.Pages.UserPage.Panels
@page "/user/{id:long?}"
@{
StringBuilder sb = new StringBuilder(" - WatchIt");
if (!_loaded) sb.Insert(0, "Loading...");
else if (_accountData is null) sb.Insert(0, "Error");
else
{
if (_owner) sb.Insert(0, "Your profile");
else sb.Insert(0, $"\"{_accountData.Username}\" profile");
}
<PageTitle>@(sb.ToString())</PageTitle>
}
<div class="container-grid">
@if (!_loaded)
{
<div class="row">
<div class="col">
<div class="m-5">
<LoadingComponent/>
</div>
</div>
</div>
}
else if (_accountData is null)
{
<div class="row">
<div class="col">
<ErrorPanelComponent ErrorMessage="@($"User with ID {Id!.Value} was not found")"/>
</div>
</div>
}
else
{
<div class="row">
<div class="col">
<UserPageHeaderPanelComponent/>
</div>
</div>
}
</div>

View File

@@ -1,7 +1,87 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts;
using WatchIt.Website.Layout;
using WatchIt.Website.Services.Authentication;
using WatchIt.Website.Services.Client.Accounts;
namespace WatchIt.Website.Pages;
public partial class UserPage : ComponentBase
{
#region SERVICES
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] private IAccountsClientService AccountsClientService { get; set; } = default!;
#endregion
#region PARAMETERS
[Parameter] public long? Id { get; set; }
[CascadingParameter] public MainLayout Layout { get; set; } = default!;
#endregion
#region FIELDS
private bool _loaded;
private bool _redirection;
private bool _owner;
private AccountResponse? _accountData;
#endregion
#region PRIVATE METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
List<Task> endTasks = new List<Task>();
// INIT
Layout.BackgroundPhoto = null;
// STEP 0
endTasks.AddRange(
[
GetUserData()
]);
// END
await Task.WhenAll(endTasks);
_loaded = !_redirection;
StateHasChanged();
}
}
private async Task GetUserData()
{
User? user = await AuthenticationService.GetUserAsync();
if (!Id.HasValue)
{
if (user is null)
{
NavigationManager.NavigateTo("/auth");
_redirection = true;
return;
}
Id = user.Id;
}
await AccountsClientService.GetAccountInfoById(Id.Value, data => _accountData = data);
_owner = Id.Value == user?.Id;
}
#endregion
}

View File

@@ -17,7 +17,7 @@
<ProjectReference Include="..\..\WatchIt.Common\WatchIt.Common.Services\WatchIt.Common.Services.HttpClient\WatchIt.Common.Services.HttpClient.csproj" />
<ProjectReference Include="..\..\WatchIt.WebAPI\WatchIt.WebAPI.Services\WatchIt.WebAPI.Services.Utility\WatchIt.WebAPI.Services.Utility.Tokens\WatchIt.WebAPI.Services.Utility.Tokens.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.Authentication\WatchIt.Website.Services.Authentication.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -58,7 +58,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Common.Query", "Wat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Common.Services.HttpClient", "WatchIt.Common\WatchIt.Common.Services\WatchIt.Common.Services.HttpClient\WatchIt.Common.Services.HttpClient.csproj", "{A4A75CCA-0DEE-4F1E-9816-60674CA807FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Website.Services.Configuration", "WatchIt.Website\WatchIt.Website.Services\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj", "{0DBBE7EA-05FE-481F-8814-6FA0BC9E571F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Website.Services.Configuration", "WatchIt.Website\WatchIt.Website.Services\WatchIt.Website.Services.Configuration\WatchIt.Website.Services.Configuration.csproj", "{0DBBE7EA-05FE-481F-8814-6FA0BC9E571F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.WebAPI.Services.Controllers.Media", "WatchIt.WebAPI\WatchIt.WebAPI.Services\WatchIt.WebAPI.Services.Controllers\WatchIt.WebAPI.Services.Controllers.Media\WatchIt.WebAPI.Services.Controllers.Media.csproj", "{3156AD7B-D6EC-4EB6-AEE8-4FBAF14C18E4}"
EndProject