Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MyBody and improve Index page performance. Use constants. #331

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BedBrigade.Client/Components/AngleImageView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.IO;
using BedBrigade.Data.Data.Seeding;

namespace BedBrigade.Client.Components
{
public partial class AngleImageView
{

[Parameter] public string Caption { get; set; } = "Bed Brigade";
[Parameter] public string Path { get; set; } = "National";
[Parameter] public string Path { get; set; } = SeedConstants.SeedNationalName;

string FileName { get; set; } = "NoImageFound.jpg";
string LeftFileName { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion BedBrigade.Client/Components/FileManager.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BedBrigade.Common.Constants;
using BedBrigade.Common.Enums;
using BedBrigade.Common.Models;
using BedBrigade.Data.Data.Seeding;

namespace BedBrigade.Client.Components
{
Expand Down Expand Up @@ -302,7 +303,7 @@ public bool isLocationFolder()
if (slashCount == 2)
{ // take text between /xxxxx/
var arLocation = folderPath.Split(PathDivider);
if (arLocation[1].ToLower() != "national") // special validation, because route "/" is national
if (arLocation[1].ToLower() != SeedConstants.SeedNationalName.ToLower()) // special validation, because route "/" is national
{
selectedLocation += arLocation[1];
}
Expand Down
3 changes: 2 additions & 1 deletion BedBrigade.Client/Components/Footer.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BedBrigade.Client.Services;
using BedBrigade.Data.Data.Seeding;
using BedBrigade.Data.Services;
using Microsoft.AspNetCore.Components;
using Serilog;
Expand Down Expand Up @@ -28,7 +29,7 @@ public void Dispose()

private async Task LoadContent()
{
string locationName = _locationState.Location ?? "National";
string locationName = _locationState.Location ?? SeedConstants.SeedNationalName;
var locationResult = await _svcLocation.GetLocationByRouteAsync($"/{locationName.ToLower()}");

if (!locationResult.Success)
Expand Down
16 changes: 14 additions & 2 deletions BedBrigade.Client/Components/Header.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Security.Claims;
using BedBrigade.Client.Services;
using BedBrigade.Common.Constants;
using BedBrigade.Common.Logic;
using BedBrigade.Data.Data.Seeding;
using BedBrigade.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
Expand Down Expand Up @@ -29,6 +31,7 @@ public partial class Header : ComponentBase, IDisposable
private string Menu { get; set; }
private AuthenticationState _authState { get; set; }
private string PreviousLocation { get; set; }
private ClaimsPrincipal User { get; set; }

protected override async Task OnInitializedAsync()
{
Expand All @@ -42,7 +45,16 @@ protected override async Task OnInitializedAsync()
private async void OnAuthenticationStateChanged(Task<AuthenticationState> task)
{
_authState = await task;
StateHasChanged();

//We don't need to refresh if this is the first time to load the component
if (User == null)
{
User = _authState.User;
}
else
{
StateHasChanged();
}
}

private async Task OnLocationChanged()
Expand All @@ -53,7 +65,7 @@ private async Task OnLocationChanged()

private async Task LoadContent()
{
string locationName = _locationState.Location ?? "National";
string locationName = _locationState.Location ?? SeedConstants.SeedNationalName;
var locationResult = await _svcLocation.GetLocationByRouteAsync($"/{locationName.ToLower()}");

if (!locationResult.Success)
Expand Down
5 changes: 3 additions & 2 deletions BedBrigade.Client/Components/MediaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BedBrigade.Common.Enums;
using BedBrigade.Common.Constants;
using BedBrigade.Common.Models;
using BedBrigade.Data.Data.Seeding;

namespace BedBrigade.Client.Components
{
Expand Down Expand Up @@ -178,10 +179,10 @@ public static void UpdateUserFolderList(ref MediaUser MediaUser)

if (MediaUser.FolderList.Count > 1)
{
if (MediaUser.Role.Contains("National"))
if (MediaUser.Role.Contains(SeedConstants.SeedNationalName))
{
// set National pre-selecterd
var nationalFolder = MediaUser.FolderList.Where(f => f.ToLower().Contains("national")).ToList();
var nationalFolder = MediaUser.FolderList.Where(f => f.ToLower().Contains(SeedConstants.SeedNationalName.ToLower())).ToList();
MediaUser.DropFileFolder = nationalFolder[0];
}
else
Expand Down
146 changes: 0 additions & 146 deletions BedBrigade.Client/Components/MyBody.razor

This file was deleted.

41 changes: 1 addition & 40 deletions BedBrigade.Client/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
@page "/"
@page "/{mylocation:nonfile}"
@page "/{mylocation}/{mypageName:nonfile}"
@using BedBrigade.Client.Services
@using Serilog

<MyBody @ref="myBody"/>
@((MarkupString)BodyContent)

@code {
MyBody myBody;
[Inject] private IJSRuntime _js { get; set; }

[Inject]
private ILocationState _locationState { get; set; }

[Parameter] public string? mylocation { get; set; }
[Parameter] public string? mypageName { get; set; }
public string location { get; set; }
public string pageName { get; set; }
const string defaultLocation = "National";
const string defaultPageName = "Home";

protected override async Task OnParametersSetAsync()
{
location = string.IsNullOrEmpty(mylocation) ? defaultLocation : mylocation;
pageName = string.IsNullOrEmpty(mypageName) ? defaultPageName : mypageName;
_locationState.Location = location;
mylocation = null;
mypageName = null;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{

string message = $"Calling {mypageName ?? defaultPageName} for location {mylocation ?? defaultLocation}";
Log.Logger.Debug(message);

if (!firstRender)
{
Log.Logger.Debug("LoadBody");
await myBody.LoadBody();
Log.Logger.Debug("RefreshState");
myBody.RefreshState();
}
}
}
Loading
Loading