Skip to content

Commit

Permalink
Display the latest announcement (if any) on the landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
sudokoko committed Mar 28, 2024
1 parent e1cc214 commit a5ba584
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
29 changes: 28 additions & 1 deletion ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,34 @@
}
}

<br><br>
@if (Model.LatestAnnouncement != null)
{
<div class="ui blue segment" style="position: relative;">
<div>
<h3>@Model.LatestAnnouncement.Title</h3>
<div style="padding-bottom: 2em;">
<span style="white-space: pre-line">
@(Model.LatestAnnouncement.Content.Length > 250
? Model.LatestAnnouncement.Content[..250] + $"... [read more]({ServerConfiguration.Instance.ExternalUrl}/notifications)"
: Model.LatestAnnouncement.Content)
</span>
</div>
@if (Model.LatestAnnouncement.Publisher != null)
{
<div class="ui tiny bottom left attached label">
Posted by
<a style="color: black" href="~/user/@Model.LatestAnnouncement.Publisher.UserId">
@Model.LatestAnnouncement.Publisher.Username
</a>
</div>
}
</div>
</div>
}
else
{
<br /><br />
}

<div class="@(isMobile ? "" : "ui center aligned grid")">
<div class="eight wide column">
Expand Down
7 changes: 7 additions & 0 deletions ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Website;
using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand All @@ -19,6 +20,8 @@ public class LandingPage : BaseLayout
public int PendingAuthAttempts;
public List<UserEntity> PlayersOnline = new();

public WebsiteAnnouncementEntity? LatestAnnouncement;

public LandingPage(DatabaseContext database) : base(database)
{ }

Expand Down Expand Up @@ -54,6 +57,10 @@ public async Task<IActionResult> OnGet()
.Include(s => s.Creator)
.ToListAsync();

this.LatestAnnouncement = await this.Database.WebsiteAnnouncements.Include(a => a.Publisher)
.OrderByDescending(a => a.AnnouncementId)
.FirstOrDefaultAsync();

return this.Page();
}
}

0 comments on commit a5ba584

Please sign in to comment.