Refactoring, database structure changed
This commit is contained in:
16
WatchIt.Website/Components/Layout/BaseLayout.razor
Normal file
16
WatchIt.Website/Components/Layout/BaseLayout.razor
Normal file
@@ -0,0 +1,16 @@
|
||||
@using Blazorise.Snackbar
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<CascadingValue Value="@(this)">
|
||||
@(Body)
|
||||
|
||||
<SnackbarStack @ref="SnackbarStack" Location="SnackbarStackLocation.Bottom" />
|
||||
|
||||
<style>
|
||||
/* TAGS */
|
||||
body {
|
||||
background-image: url('@(Background?.ToString() ?? "assets/placeholders/background.jpg")');
|
||||
}
|
||||
</style>
|
||||
</CascadingValue>
|
||||
123
WatchIt.Website/Components/Layout/BaseLayout.razor.cs
Normal file
123
WatchIt.Website/Components/Layout/BaseLayout.razor.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System.Drawing;
|
||||
using Blazorise.Snackbar;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Accounts.Account;
|
||||
using WatchIt.DTO.Models.Controllers.Photos.Photo;
|
||||
using WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
|
||||
using WatchIt.Website.Clients;
|
||||
using WatchIt.Website.Services.Authentication;
|
||||
|
||||
namespace WatchIt.Website.Components.Layout;
|
||||
|
||||
public partial class BaseLayout : LayoutComponentBase
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
|
||||
[Inject] private IPhotosClient PhotosClient { get; set; } = null!;
|
||||
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private static readonly PhotoBackgroundResponse StaticBackgroundSettings = new PhotoBackgroundResponse()
|
||||
{
|
||||
IsUniversal = true,
|
||||
FirstGradientColor = Color.FromArgb(0xc6, 0x72, 0x1c),
|
||||
SecondGradientColor = Color.FromArgb(0x85, 0x20, 0x0c),
|
||||
};
|
||||
|
||||
private PhotoResponse? _defaultBackground;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PROPERTIES
|
||||
|
||||
private PhotoResponse? _customBackground;
|
||||
public PhotoResponse? CustomBackground
|
||||
{
|
||||
get => _customBackground;
|
||||
set
|
||||
{
|
||||
_customBackground = value;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
public PhotoResponse? Background
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CustomBackground?.Background is not null)
|
||||
{
|
||||
return CustomBackground;
|
||||
}
|
||||
return _defaultBackground?.Background is not null ? _defaultBackground : null;
|
||||
}
|
||||
}
|
||||
public PhotoBackgroundResponse BackgroundSettings => Background is null ? StaticBackgroundSettings : Background.Background!;
|
||||
|
||||
public AccountResponse? AuthorizedAccount { get; private set; }
|
||||
public bool AuthorizationLoaded { get; private set; }
|
||||
|
||||
public SnackbarStack SnackbarStack { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public async Task RefreshAuthorization()
|
||||
{
|
||||
long? accountId = await AuthenticationService.GetAccountIdAsync();
|
||||
if (accountId.HasValue)
|
||||
{
|
||||
IApiResponse<AccountResponse> accountResponse = await AccountsClient.GetAccount(accountId.Value, true);
|
||||
if (accountResponse.IsSuccessful)
|
||||
{
|
||||
AuthorizedAccount = accountResponse.Content;
|
||||
}
|
||||
}
|
||||
AuthorizationLoaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (firstRender)
|
||||
{
|
||||
await OnFirstRenderAsync();
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task OnFirstRenderAsync() => await Task.WhenAll(
|
||||
[
|
||||
GetBackground(),
|
||||
RefreshAuthorization(),
|
||||
]);
|
||||
|
||||
protected async Task GetBackground()
|
||||
{
|
||||
IApiResponse<PhotoResponse?> response = await PhotosClient.GetPhotoBackground();
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
_defaultBackground = response.Content;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
7
WatchIt.Website/Components/Layout/EmptyLayout.razor
Normal file
7
WatchIt.Website/Components/Layout/EmptyLayout.razor
Normal file
@@ -0,0 +1,7 @@
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@layout BaseLayout
|
||||
|
||||
|
||||
|
||||
@(Body)
|
||||
110
WatchIt.Website/Components/Layout/MainLayout.razor
Normal file
110
WatchIt.Website/Components/Layout/MainLayout.razor
Normal file
@@ -0,0 +1,110 @@
|
||||
@using System.Drawing
|
||||
@using System.Net
|
||||
@using WatchIt.Website.Components.Subcomponents.Common
|
||||
@using Blazorise
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using WatchIt.DTO.Models.Controllers.Genres.Genre
|
||||
@using Size = Blazorise.Size
|
||||
@using Color = Blazorise.Color
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@layout BaseLayout
|
||||
|
||||
|
||||
|
||||
<div class="container-xl">
|
||||
<div class="row sticky-top top-3 mb-2rem">
|
||||
<div class="col">
|
||||
<div class="panel panel-header">
|
||||
<div class="container-grid">
|
||||
<div class="row align-items-center">
|
||||
<div class="col">
|
||||
<a id="logo" class="logo default-gradient" href="/">
|
||||
WatchIt
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
@if (_searchbarVisible)
|
||||
{
|
||||
<Searchbar OnCloseButtonClicked="@(() => _searchbarVisible = false)"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<Dropdown>
|
||||
<DropdownToggle Color="Color.Default" Size="Size.Small" ToggleIconVisible="false">Database</DropdownToggle>
|
||||
<DropdownMenu>
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/media/movies"))">Movies</DropdownItem>
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/media/series"))">TV Series</DropdownItem>
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/people"))">People</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
@if (_genres.Any())
|
||||
{
|
||||
<Dropdown>
|
||||
<DropdownToggle Color="Color.Default" Size="Size.Small" ToggleIconVisible="false">Genres</DropdownToggle>
|
||||
<DropdownMenu MaxMenuHeight="250px">
|
||||
@foreach (GenreResponse genre in _genres)
|
||||
{
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo($"/genres/{genre.Id}/media", true))">@(genre.Name)</DropdownItem>
|
||||
}
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
}
|
||||
<button type="button" class="btn btn-sm" @onclick="@(() => _searchbarVisible = true)">⌕</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="float-end">
|
||||
<Authorization>
|
||||
<Authorized>
|
||||
<Dropdown RightAligned>
|
||||
<Button Color="Color.Default" Clicked="@(() => NavigationManager.NavigateTo($"/users/{BaseLayout.AuthorizedAccount!.Id}"))">
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<AccountPicture Item="@(BaseLayout.AuthorizedAccount!)" Size="30"/>
|
||||
<span>@(BaseLayout.AuthorizedAccount!.Username)</span>
|
||||
</div>
|
||||
</Button>
|
||||
<DropdownToggle Color="Color.Default" Split />
|
||||
<DropdownMenu>
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo($"/users/{BaseLayout.AuthorizedAccount!.Id}"))">Your profile</DropdownItem>
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/user_settings"))">User settings</DropdownItem>
|
||||
@if (BaseLayout.AuthorizedAccount!.IsAdmin)
|
||||
{
|
||||
<DropdownDivider/>
|
||||
<DropdownItem Clicked="@(() => NavigationManager.NavigateTo("/admin"))">Administrator panel</DropdownItem>
|
||||
}
|
||||
<DropdownDivider/>
|
||||
<DropdownItem TextColor="TextColor.Danger" Clicked="@(Logout)">Log out</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<a class="main-button default-gradient" href="/auth?redirect_to=@(WebUtility.UrlEncode(NavigationManager.Uri))">Sign in</a>
|
||||
</NotAuthorized>
|
||||
<Loading>
|
||||
<LoadingInline/>
|
||||
</Loading>
|
||||
</Authorization>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row pt-3 pb-3">
|
||||
<div class="col">
|
||||
@Body
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* CLASS */
|
||||
.default-gradient {
|
||||
background-image: linear-gradient(45deg, @($"{ColorTranslator.ToHtml(BaseLayout.BackgroundSettings.FirstGradientColor)}, {ColorTranslator.ToHtml(BaseLayout.BackgroundSettings.SecondGradientColor)}"));
|
||||
}
|
||||
</style>
|
||||
68
WatchIt.Website/Components/Layout/MainLayout.razor.cs
Normal file
68
WatchIt.Website/Components/Layout/MainLayout.razor.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Blazorise.Snackbar;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Genres.Genre;
|
||||
using WatchIt.Website.Clients;
|
||||
using WatchIt.Website.Services.Authentication;
|
||||
|
||||
namespace WatchIt.Website.Components.Layout;
|
||||
|
||||
public partial class MainLayout : LayoutComponentBase
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
|
||||
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
|
||||
[Inject] private IGenresClient GenresClient { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private bool _searchbarVisible;
|
||||
|
||||
private IEnumerable<GenreResponse> _genres = [];
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PARAMETERS
|
||||
|
||||
[CascadingParameter] public required BaseLayout BaseLayout { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await OnFirstRenderAsync();
|
||||
}
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
protected async Task OnFirstRenderAsync()
|
||||
{
|
||||
IApiResponse<IEnumerable<GenreResponse>> genresResponse = await GenresClient.GetGenres();
|
||||
switch (genresResponse.IsSuccessful)
|
||||
{
|
||||
case true: _genres = genresResponse.Content; break;
|
||||
case false: await BaseLayout.SnackbarStack.PushAsync("An error occured. Genres could not be loaded", SnackbarColor.Danger); break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
await AuthenticationService.Logout();
|
||||
NavigationManager.Refresh(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
5
WatchIt.Website/Components/Layout/MainLayout.razor.css
Normal file
5
WatchIt.Website/Components/Layout/MainLayout.razor.css
Normal file
@@ -0,0 +1,5 @@
|
||||
/* IDS */
|
||||
|
||||
#logo {
|
||||
font-size: 40px;
|
||||
}
|
||||
Reference in New Issue
Block a user