From 396edeefde084031864580627a44be506a920543 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Sat, 18 Mar 2023 00:49:50 +0100 Subject: [PATCH] feat: started working on replys in comments, changes IDs to GETs Signed-off-by: limited_dev --- .../Data/Repository/CommentsRepository.cs | 13 +++ .../Data/Repository/PostsRepository.cs | 13 +++ .../Pages/Basic/ThreadPage.razor | 2 +- .../Shared/Components/Comment.razor.css | 4 +- .../Shared/Components/CommentHover.razor | 90 +++++++++++++++++++ .../Shared/Components/CommentHover.razor.css | 75 ++++++++++++++++ .../Shared/Components/Post.razor | 14 +-- .../Shared/Components/Post.razor.css | 2 +- ImageBoardServerApp/Util/TheManager.cs | 5 ++ 9 files changed, 207 insertions(+), 11 deletions(-) create mode 100644 ImageBoardServerApp/Shared/Components/CommentHover.razor create mode 100644 ImageBoardServerApp/Shared/Components/CommentHover.razor.css diff --git a/ImageBoardServerApp/Data/Repository/CommentsRepository.cs b/ImageBoardServerApp/Data/Repository/CommentsRepository.cs index 83d3384..9ce47ee 100644 --- a/ImageBoardServerApp/Data/Repository/CommentsRepository.cs +++ b/ImageBoardServerApp/Data/Repository/CommentsRepository.cs @@ -31,6 +31,19 @@ public static class CommentsRepository .FirstOrDefaultAsync(); } + public static async Task getCommentByGETAsync(string board, int get) + { + await using var db = new AppDBContext(); + return await db.Comments + .Where(comment => comment.GET == get) + .Where(comment => comment.Board == board) + .Include(comment => comment.Image) + .Include(comment => comment.Post) + .Include(comment => comment.User) + .Include(comment => comment.Report) + .FirstOrDefaultAsync(); + } + /*public static async Task getPostByIdAsync(int postId) { await using var db = new AppDBContext(); diff --git a/ImageBoardServerApp/Data/Repository/PostsRepository.cs b/ImageBoardServerApp/Data/Repository/PostsRepository.cs index ec0e024..5d97101 100644 --- a/ImageBoardServerApp/Data/Repository/PostsRepository.cs +++ b/ImageBoardServerApp/Data/Repository/PostsRepository.cs @@ -32,6 +32,19 @@ public static class PostsRepository .FirstOrDefaultAsync(); //return await db.Posts.FirstOrDefaultAsync(post => post.PostID == postId); } + + public static async Task getPostByGETAsync(string board, int get) + { + await using var db = new AppDBContext(); + return await db.Posts + .Where(post => post.GET == get) + .Where(post => post.Board == board) + .Include(post => post.Image) + .Include(post => post.Comments) + .Include(post => post.User) + .FirstOrDefaultAsync(); + //return await db.Posts.FirstOrDefaultAsync(post => post.PostID == postId); + } public static async Task createPostAsync(PostData postToCreate) { diff --git a/ImageBoardServerApp/Pages/Basic/ThreadPage.razor b/ImageBoardServerApp/Pages/Basic/ThreadPage.razor index 71955c3..e35d125 100644 --- a/ImageBoardServerApp/Pages/Basic/ThreadPage.razor +++ b/ImageBoardServerApp/Pages/Basic/ThreadPage.razor @@ -33,7 +33,7 @@ { try { - post = await PostsRepository.getPostByIdAsync(int.Parse(threadId)); + post = await PostsRepository.getPostByGETAsync(boardName, int.Parse(threadId)); } catch (FormatException fe) { diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor.css b/ImageBoardServerApp/Shared/Components/Comment.razor.css index fc40707..d6a2065 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor.css +++ b/ImageBoardServerApp/Shared/Components/Comment.razor.css @@ -17,7 +17,7 @@ } .redText { - color: #a91e1e; + color: #da1313; } @@ -51,7 +51,7 @@ width: 100%; } -.threadImage img:hover{ +.threadImage img.active{ /*transform: scale(3);*/ max-width:500px; width: 100%; diff --git a/ImageBoardServerApp/Shared/Components/CommentHover.razor b/ImageBoardServerApp/Shared/Components/CommentHover.razor new file mode 100644 index 0000000..b6e27e7 --- /dev/null +++ b/ImageBoardServerApp/Shared/Components/CommentHover.razor @@ -0,0 +1,90 @@ +@using System.Text.RegularExpressions +@using ImageBoardServerApp.Data.Repository +@using System.ComponentModel.DataAnnotations +@comment.Username +@if (@role != "User") +{ + ##@role +} +else +{ + +} +@getTimeFromUnix(comment.CreatedAt) +No.@comment.GET +
+
+ @if (image != null) + { + No Image found + } +
+
+ @foreach (string s in @comment.Content.Split("\n")) + { + var className = ""; + @if (s.StartsWith(">") && !Regex.IsMatch(s, "^>{2,}")) + { + className = "greenText"; + } + + + @foreach (string line in s.Split(" ")) + { + var className2 = ""; + @if (@Regex.IsMatch(line, ">>\\d+")) + { + className2 = "redText"; + >(\\d+)").Value.Substring(2)" class="threadMsg @className2"> + @line + + } + else + { + + @line + + } +   + + } + + } +
+
+@code { + private ImageData image; + private string role; + + private static DateTime getTimeFromUnix(double javaTimeStamp) + { + var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + dateTime = dateTime.AddMilliseconds( javaTimeStamp ).ToLocalTime(); + return dateTime; + } + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + int i; + try + { + i = (int)comment.ImageID; + } + catch (InvalidOperationException ioe) + { + i = -1; + } + if (i != null) + { + image = await ImagesRepository.getImageByIdAsync(i); + } + + var cmt = await CommentsRepository.getCommentByIdAsync(comment.CommentID); + role = cmt.User.Role; + } + + [Parameter] + [Required] + public CommentData comment { get; set; } +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/CommentHover.razor.css b/ImageBoardServerApp/Shared/Components/CommentHover.razor.css new file mode 100644 index 0000000..0398886 --- /dev/null +++ b/ImageBoardServerApp/Shared/Components/CommentHover.razor.css @@ -0,0 +1,75 @@ +.toggleOpened{ + color: #0a58ca; + text-decoration: none; +} + +.toggleOpened:hover{ + color: #0a58ca; !important; + cursor: pointer; +} + +.title{ + color: #1e5aaf; +} + +.name{ + color: #339305; +} + +.redText { + color: #da1313; +} + + +.threadHeader{ + text-align: left; +} + +.threadFooter{ + text-align: right; !important; + align-self: end; !important; +} + +.threadContent{ + text-align: left; + display: flex; +} + +.greenText{ + color: #3caf03; +} + +.threadImage{ + margin: 6px; + max-width: 500px; + max-height: 500px; + padding: 5px; +} + +.threadImage img{ + max-width:150px; + width: 100%; +} + +.threadImage img:hover{ + /*transform: scale(3);*/ + max-width:500px; + width: 100%; +} + +.threadText{ + display: block; +} + +.threadTextContainer{ + margin: 0; +} + + +.Admin{ + color: #ff191c; +} + +.Mod{ + color: #af13d7; +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Post.razor b/ImageBoardServerApp/Shared/Components/Post.razor index e4f5e65..271ba8a 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor +++ b/ImageBoardServerApp/Shared/Components/Post.razor @@ -1,9 +1,7 @@ -@using System.ComponentModel.DataAnnotations -@using System.Text.RegularExpressions -@using ImageBoardServerApp.Auth -@using ImageBoardServerApp.Data +@using System.Text.RegularExpressions @using ImageBoardServerApp.Data.Repository -@using Microsoft.AspNetCore.Html +@using ImageBoardServerApp.Auth +@using System.ComponentModel.DataAnnotations @inject AuthenticationStateProvider authStateProvider @inject NavigationManager navigationManager; @@ -45,7 +43,8 @@
@if (@post.Image != null) { - No Image found + string isActiveClass = isActive ? "active" : ""; + No Image found } else { @@ -105,7 +104,7 @@ @if (showOpenThread) { [ - (@post.Comments.Count) View Thread + (@post.Comments.Count) View Thread ] } else @@ -122,6 +121,7 @@ @code { public bool canDel { get; set; } + public bool isActive { get; set; } = false; private async void lockMe() { diff --git a/ImageBoardServerApp/Shared/Components/Post.razor.css b/ImageBoardServerApp/Shared/Components/Post.razor.css index a0be3b3..3672759 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor.css +++ b/ImageBoardServerApp/Shared/Components/Post.razor.css @@ -54,7 +54,7 @@ width: 100%; } -.threadImage img:hover{ +.threadImage img.active{ /*transform: scale(3);*/ max-width:500px; width: 100%; diff --git a/ImageBoardServerApp/Util/TheManager.cs b/ImageBoardServerApp/Util/TheManager.cs index 9d06061..53a7224 100644 --- a/ImageBoardServerApp/Util/TheManager.cs +++ b/ImageBoardServerApp/Util/TheManager.cs @@ -87,4 +87,9 @@ public class TheManager Console.WriteLine("An error occurred: " + e.Message); } } + + public static async Task isGETComment(string board, int GET) + { + return await CommentsRepository.getCommentByGETAsync(board, GET) != null; + } } \ No newline at end of file