From bc8385a9e63253a3190b08467cbf31d0256053e8 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 11 Aug 2023 02:57:35 +1000 Subject: Added basis for a search box --- Pages/Index.cshtml.cs | 32 ++++++++++++++++++++++++++++++-- Pages/Shared/_Layout.cshtml | 1 + Pages/Shared/_Layout.cshtml.css | 12 ++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) (limited to 'Pages') diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs index e03a330..07d24f0 100644 --- a/Pages/Index.cshtml.cs +++ b/Pages/Index.cshtml.cs @@ -4,12 +4,40 @@ using Microsoft.AspNetCore.Mvc.RazorPages; namespace HyperBooru.Pages; public class IndexModel : PageModel { - public IEnumerable Media => db.Media; + public IEnumerable Media { get; private set; } private HyperBooruDbContext db; public IndexModel(HyperBooruDbContext db) => this.db = db; - public void OnGet() {} + public void OnGet([FromQuery(Name = "q")] string? query) { + IEnumerable media; + + if(query is null) { + media = db.UploadedFiles + .OrderByDescending(uf => uf.UploadTime) + .Select(uf => uf.Media) + .Distinct(); + } else { + query = query.ToLower(); + + var matchingTags = db.TagDefinitions + .Where(td => td.Name.ToLower().Contains(query)) + .Select(td => td.Guid); + + media = db.Media + .Where(m => + m.Tags + .Select(t => t.TagDefinition.Guid) + .Intersect(matchingTags) + .Any()); + } + + Media = media.OrderByDescending(m => + m.UploadedFiles + .Select(uf => uf.UploadTime) + .Order() + .Last()); + } } \ No newline at end of file diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index 4c80500..9d6d382 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -17,6 +17,7 @@
@RenderBody() diff --git a/Pages/Shared/_Layout.cshtml.css b/Pages/Shared/_Layout.cshtml.css index 22e36db..5b2f26e 100644 --- a/Pages/Shared/_Layout.cshtml.css +++ b/Pages/Shared/_Layout.cshtml.css @@ -1,6 +1,7 @@ div#navbar { background: var(--col-navbar-bg); box-shadow: rgba(0, 0, 0, 0.5) 0px 10px 10px; + display: flex; } div#navbar > a { @@ -19,6 +20,17 @@ div#navbar > a:active { color: var(--col-navbar-bg); } +div#navbar > input { + align-self: center; + background: var(--col-bg); + border-radius: 0; + color: white; + height: 40px !important; + margin: 0 20px 0 auto; + font-size: 12pt; + min-width: 30%; +} + #content { flex: 1 1 calc(100vh - 119px); } \ No newline at end of file -- cgit v1.3