From 213db4f2d84d13ba170e439a80ed0b591d87ac08 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 3 Apr 2022 19:07:36 -0400 Subject: [PATCH] Add teampicks and trending levels on landing page Rough implementation for https://github.com/LBPUnion/ProjectLighthouse/issues/241 --- ProjectLighthouse/Pages/LandingPage.cshtml | 38 ++++++++++++++- ProjectLighthouse/Pages/LandingPage.cshtml.cs | 46 ++++++++++++++++++- .../Pages/Partials/SlotCardPartial.cshtml | 40 ++++++++++++---- 3 files changed, 112 insertions(+), 12 deletions(-) diff --git a/ProjectLighthouse/Pages/LandingPage.cshtml b/ProjectLighthouse/Pages/LandingPage.cshtml index 47735d4c..d48da0f5 100644 --- a/ProjectLighthouse/Pages/LandingPage.cshtml +++ b/ProjectLighthouse/Pages/LandingPage.cshtml @@ -1,11 +1,14 @@ @page "/" +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @using LBPUnion.ProjectLighthouse.Types +@using LBPUnion.ProjectLighthouse.Types.Levels @using LBPUnion.ProjectLighthouse.Types.Settings @model LBPUnion.ProjectLighthouse.Pages.LandingPage @{ Layout = "Layouts/BaseLayout"; Model.ShowTitleInPage = false; + bool isMobile = this.Request.IsMobile(); }

Welcome to Project Lighthouse!

@@ -40,4 +43,37 @@ else { @user.Username } -} \ No newline at end of file +} + +
+
+
+

Latest Team Picks

+
+
+ @foreach (Slot slot in Model.LatestTeamPicks) + { + @await Html.PartialAsync("Partials/SlotCardPartial", slot, Model.GetSlotViewData(slot.SlotId, isMobile)) +
+ } +
+
+
+ @if (isMobile) + { +
+ } +
+
+

Trending Levels

+
+
+ @foreach (Slot slot in Model.TrendingLevels) + { + @await Html.PartialAsync("Partials/SlotCardPartial", slot, Model.GetSlotViewData(slot.SlotId, isMobile)) +
+ } +
+
+
+
\ No newline at end of file diff --git a/ProjectLighthouse/Pages/LandingPage.cshtml.cs b/ProjectLighthouse/Pages/LandingPage.cshtml.cs index 0d23a58e..8cd35a1d 100644 --- a/ProjectLighthouse/Pages/LandingPage.cshtml.cs +++ b/ProjectLighthouse/Pages/LandingPage.cshtml.cs @@ -6,20 +6,25 @@ using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; +using LBPUnion.ProjectLighthouse.Types.Levels; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.EntityFrameworkCore; namespace LBPUnion.ProjectLighthouse.Pages; public class LandingPage : BaseLayout { + public LandingPage(Database database) : base(database) + {} public int AuthenticationAttemptsCount; public List PlayersOnline; public int PlayersOnlineCount; - public LandingPage(Database database) : base(database) - {} + + public List LatestTeamPicks; + public List TrendingLevels; [UsedImplicitly] public async Task OnGet() @@ -37,6 +42,43 @@ public class LandingPage : BaseLayout List userIds = await this.Database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync(); this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync(); + + const int maxShownLevels = 5; + + this.LatestTeamPicks = await this.Database.Slots.Where + (s => s.TeamPick) + .OrderBy(s => s.FirstUploaded) + .Take(maxShownLevels) + .Include(s => s.Creator) + .ToListAsync(); + + this.TrendingLevels = await this.Database.Slots.OrderByDescending + (s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique + s.PlaysLBPVitaUnique) + .ThenBy(s => s.FirstUploaded) + .Take(maxShownLevels) + .Include(s => s.Creator) + .ToListAsync(); + return this.Page(); } + + public ViewDataDictionary GetSlotViewData(int slotId, bool isMobile = false) + => new(ViewData) + { + { + "User", this.User + }, + { + "CallbackUrl", $"~/slot/{slotId}" + }, + { + "ShowLink", true + }, + { + "IsMini", true + }, + { + "IsMobile", isMobile + }, + }; } \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml index 36318404..c6891995 100644 --- a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml @@ -12,6 +12,8 @@ string slotName = string.IsNullOrEmpty(Model.Name) ? "Unnamed Level" : Model.Name; bool isMobile = (bool?)ViewData["IsMobile"] ?? false; + bool mini = (bool?)ViewData["IsMini"] ?? false; + bool isQueued = false; bool isHearted = false; @@ -30,25 +32,44 @@ }
@{ - int size = isMobile ? 50 : 100; + int size = isMobile || mini ? 50 : 100; }
- @if (showLink) + @if (!mini) { -

- @slotName -

+ @if (showLink) + { +

+ @slotName +

+ } + else + { +

+ @slotName +

+ } } else { -

- @slotName -

+ @if (showLink) + { +

+ @slotName +

+ } + else + { +

+ @slotName +

+ } } +
@Model.Hearts @Model.Plays @@ -61,13 +82,14 @@ @Model.RatingLBP1 }
+

Created by @Model.Creator?.Username for @Model.GameVersion.ToPrettyString()


- @if (user != null) + @if (user != null && !mini) { if (isHearted) {