Skip to content

Commit

Permalink
Merge pull request #413 from GregFinzer/featurePageTitles
Browse files Browse the repository at this point in the history
Page Titles
  • Loading branch information
GregFinzer authored Oct 16, 2024
2 parents 7141e40 + f24c8b8 commit 99feae0
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions BedBrigade.Client/Components/Pages/BedBrigadeNearMe.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@page "/bed-brigade-near-me"

<PageTitle>@($"{_lc.Keys["TheBedBrigade"]} | {_lc.Keys["FindABedBrigade"]}")</PageTitle>
<SearchLocation Title="@_lc.Keys["FindABedBrigade"]" />

@code {
Expand Down
2 changes: 1 addition & 1 deletion BedBrigade.Client/Components/Pages/BedRequest.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page "/request-bed"

<PageTitle>@($"{_lc.Keys["TheBedBrigade"]} | {_lc.Keys["RequestABed"]}")</PageTitle>
<RotatorContainer RotatorTitle="@_lc.Keys["RequestABed"]" ImagePath="pages/RequestBed" LocationId="1" />


Expand Down
1 change: 1 addition & 0 deletions BedBrigade.Client/Components/Pages/ContactUs.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/contact-us"
<PageTitle>@($"{_lc.Keys["TheBedBrigade"]} | {_lc.Keys["ContactUs"]}")</PageTitle>

<RotatorContainer RotatorTitle="@_lc.Keys["ContactUs"]" ImagePath="pages/Contact" LocationId="1" />

Expand Down
2 changes: 2 additions & 0 deletions BedBrigade.Client/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
@page "/{mylocation:nonfile}"
@page "/{mylocation}/{mypageName:nonfile}"

<PageTitle>@CurrentPageTitle</PageTitle>

@((MarkupString)BodyContent)


42 changes: 40 additions & 2 deletions BedBrigade.Client/Components/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using BedBrigade.Common.Models;
using KellermanSoftware.NetEmailValidation;
using BedBrigade.Common.Constants;
using BedBrigade.SpeakIt;

namespace BedBrigade.Client.Components.Pages
{
Expand All @@ -30,6 +31,8 @@ public partial class Index : ComponentBase, IDisposable

[Inject] private ILanguageService _svcLanguage { get; set; }

[Inject] private ITranslationDataService _translateLogic { get; set; }

[Parameter] public string? mylocation { get; set; }
[Parameter] public string? mypageName { get; set; }

Expand All @@ -38,7 +41,9 @@ public partial class Index : ComponentBase, IDisposable

private string previousLocation = SeedConstants.SeedNationalName;
private string previousPageName = defaultPageName;
private string PreviousBodyContent = null;
private string BodyContent = string.Empty;
private string CurrentPageTitle = string.Empty;
private string SorryPageUrl = String.Empty;

protected override async Task OnInitializedAsync()
Expand Down Expand Up @@ -135,7 +140,26 @@ private async Task<bool> LoadContentByLanguage(string location, string pageName,
{
var path = $"/{location}/pages/{pageName}";
string html = _loadImagesService.SetImagesForHtml(path, contentResult.Data.ContentHtml);
BodyContent = html;

if (html != PreviousBodyContent)
{
PreviousBodyContent = html;
BodyContent = html;
}


if (locationResponse.Data.LocationId == Defaults.NationalLocationId)
{
string bedBrigade = await _translateLogic.GetTranslation("The Bed Brigade", _svcLanguage.CurrentCulture.Name);
string title = await _translateLogic.GetTranslation(contentResult.Data.Title, _svcLanguage.CurrentCulture.Name);
CurrentPageTitle = $"{bedBrigade} | {title}";
}
else
{
string locationName = await _translateLogic.GetTranslation(locationResponse.Data.Name, _svcLanguage.CurrentCulture.Name);
string title = await _translateLogic.GetTranslation(contentResult.Data.Title, _svcLanguage.CurrentCulture.Name);
CurrentPageTitle = $"{locationName} | {title}";
}
return true;
}

Expand All @@ -149,7 +173,21 @@ private async Task<bool> LoadDefaultContent(string location, string pageName, Se
{
var path = $"/{location}/pages/{pageName}";
string html = _loadImagesService.SetImagesForHtml(path, contentResult.Data.ContentHtml);
BodyContent = html;

if (html != PreviousBodyContent)
{
PreviousBodyContent = html;
BodyContent = html;
}

if (locationResponse.Data.LocationId == Defaults.NationalLocationId)
{
CurrentPageTitle = $"The Bed Brigade | {contentResult.Data.Title}";
}
else
{
CurrentPageTitle = $"{locationResponse.Data.Name} | {contentResult.Data.Title}";
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions BedBrigade.Client/Components/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@page "/login/{user}"
@page "/login/{user}/{password}"

<PageTitle>@($"{_lc.Keys["TheBedBrigade"]} | {_lc.Keys["LogIn"]}")</PageTitle>

@using BedBrigade.Client.Components

Expand Down
3 changes: 3 additions & 0 deletions BedBrigade.Client/Components/Pages/Unauthorized.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@page "/unauthorized"

<PageTitle>@($"{_lc.Keys["TheBedBrigade"]} | {_lc.Keys["Unauthorized"]}")</PageTitle>

<h1>@_lc.Keys["SorryYouAreNot"]</h1>

@code
Expand Down
1 change: 1 addition & 0 deletions BedBrigade.Client/Components/Pages/VolunteerSignUp.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@page "/volunteer"
@using BedBrigade.Common.Models
<PageTitle>@($"{_lc.Keys["TheBedBrigade"]} | {_lc.Keys["VolunteerRegistration"]}")</PageTitle>

<RotatorContainer RotatorTitle="@_lc.Keys["VolunteerRegistration"]" ImagePath="pages/Volunteer" LocationId="1" />

Expand Down
2 changes: 2 additions & 0 deletions BedBrigade.Client/Resources/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ SuitepoBox: Suite/PO Box
TaxFormSent: Tax Form Sent
Team: 'Team #'
ThankYou: Thank you!
TheBedBrigade: The Bed Brigade
TransactionId: Transaction ID
Unauthorized: Unauthorized
UserName: User Name
ValidEmail: Please enter a valid email address
ValidPhoneNumber: Phone numbers must be 10 digits with a valid area code and prefix
Expand Down
4 changes: 3 additions & 1 deletion BedBrigade.Client/Resources/es-MX.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ReturnToHome: Volver a casa
Role: Rol
Route: Ruta
Save: Salvar
Scheduling: Programación
Scheduling: Planificación
SeachAVolunteerBy: Buscar a un voluntario por su nombre
Search: Buscar
SearchBedBrigadeLocations: Buscar ubicaciones de Bed Brigade
Expand Down Expand Up @@ -207,7 +207,9 @@ SuitepoBox: Suite/Apartado de correos
TaxFormSent: Formulario de impuestos enviado
Team: 'Equipo #'
ThankYou: ¡Gracias!
TheBedBrigade: La Brigada de la Cama
TransactionId: ID de transacción
Unauthorized: Desautorizado
UserName: Nombre de usuario
ValidEmail: Introduzca una dirección de correo electrónico válida
ValidPhoneNumber: Los números de teléfono deben tener 10 dígitos con un código de área y un prefijo válidos
Expand Down
1 change: 1 addition & 0 deletions BedBrigade.Data/Services/ITranslationDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace BedBrigade.Data.Services
public interface ITranslationDataService : IRepository<Translation>
{
Task<ServiceResponse<List<Translation>>> GetTranslationsForLanguage(string languageCode);
Task<string> GetTranslation(string? value, string languageCode);
}
}
37 changes: 36 additions & 1 deletion BedBrigade.Data/Services/TranslationDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,55 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using System.Data.Common;
using BedBrigade.SpeakIt;

namespace BedBrigade.Data.Services
{
public class TranslationDataService : Repository<Translation>, ITranslationDataService
{
private readonly IDbContextFactory<DataContext> _contextFactory;
private readonly ICachingService _cachingService;
private readonly ITranslateLogic _translateLogic;

public TranslationDataService(IDbContextFactory<DataContext> contextFactory,
ICachingService cachingService,
IAuthService authService) : base(contextFactory, cachingService, authService)
IAuthService authService, ITranslateLogic translateLogic) : base(contextFactory, cachingService, authService)
{
_contextFactory = contextFactory;
_cachingService = cachingService;
_translateLogic = translateLogic;
}

//This will attempt to get the translation using the language container and then the list of translations in the database
public async Task<string> GetTranslation(string? value, string languageCode)
{
if (string.IsNullOrWhiteSpace(value))
{
return string.Empty;
}

var resourceTranslation = _translateLogic.GetTranslation(value);

if (resourceTranslation != value)
{
return resourceTranslation;
}

var translationsForLanguage = await GetTranslationsForLanguage(languageCode);
if (!translationsForLanguage.Success || translationsForLanguage.Data == null)
{
return value;
}

var hash = _translateLogic.ComputeSHA512Hash(value);
var translation = translationsForLanguage.Data.FirstOrDefault(t => t.Hash == hash);

if (translation == null)
{
return value;
}

return translation.Content;
}

public async Task<ServiceResponse<List<Translation>>> GetTranslationsForLanguage(string languageCode)
Expand Down

0 comments on commit 99feae0

Please sign in to comment.