From d2657d28b4d49fd4d47bc1393df448db7d390582 Mon Sep 17 00:00:00 2001 From: aronmal Date: Sat, 18 Mar 2023 00:52:30 +0100 Subject: [PATCH] feat: finished implementing replying Signed-off-by: limited_dev --- .../Shared/Components/Comment.razor | 99 +++++++++++++++++-- 1 file changed, 89 insertions(+), 10 deletions(-) diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor b/ImageBoardServerApp/Shared/Components/Comment.razor index 43beaa6..a43af9f 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor +++ b/ImageBoardServerApp/Shared/Components/Comment.razor @@ -1,8 +1,7 @@ -@using System.ComponentModel.DataAnnotations @using System.Text.RegularExpressions @using ImageBoardServerApp.Auth -@using ImageBoardServerApp.Data @using ImageBoardServerApp.Data.Repository +@using System.ComponentModel.DataAnnotations @inject AuthenticationStateProvider authStateProvider
@@ -23,28 +22,52 @@
@if (image != null) { - No Image found + string isActiveClass = isActive ? "active" : ""; + No Image found }
- @foreach (string s in @comment.Content.Split("\n")) + @for (var y = 0; y < comment.Content.Split("\n").Length; y++) { + var s = comment.Content.Split("\n")[y]; var className = ""; + @if (s.StartsWith(">") && !Regex.IsMatch(s, "^>{2,}")) { className = "greenText"; } - - @foreach (string line in s.Split(" ")) - { - var className2 = ""; + @for (var x = 0; x < s.Split(" ").Length; x++) + { + var line = s.Split(" ")[x]; @if (@Regex.IsMatch(line, ">>\\d+")) { + var className2 = ""; + var x1 = x; + var y1 = y; + var commentNumber = int.Parse(Regex.Match(s, ">>(\\d+)").Value.Substring(2)); className2 = "redText"; - >(\\d+)").Value.Substring(2)" class="threadMsg @className2"> + @line - + + @if (hoveringOver.p != -1 && hoveringOver == (x, y, commentNumber)) + { + @if (isComment[commentNumber]) + { +
+ +
+ } + else + { +
+ +
+ } + } } else { @@ -73,6 +96,19 @@ @code { + private bool isActive { get; set; } = false; + + private (int x, int y, int p) hoveringOver { get; set; } = (-1, -1, -1); + private Dictionary isComment{ get; set; } + private Dictionary hoverComment { get; set; } + private Dictionary hoverPost { get; set; } + private Dictionary nrToGet { get; set; } + + private void onHover(int x, int y, int p) + { + hoveringOver = (x, y, p); + } + public bool canDel { get; set; } private async Task deletePost() @@ -110,6 +146,41 @@ canDel = true; } canDel = false; + + hoverComment = new Dictionary(); + hoverPost = new Dictionary(); + nrToGet = new Dictionary(); + isComment = new Dictionary(); + + foreach (string s in comment.Content.Split("\n")) + { + @foreach (string line in s.Split(" ")) + { + @if (Regex.IsMatch(line, ">>\\d+")) + { + var commentNumber = int.Parse(Regex.Match(s, ">>(\\d+)").Value.Substring(2)); + string board = comment.Board; + if (await TheManager.isGETComment(board, commentNumber)) + { + CommentData c = await CommentsRepository.getCommentByGETAsync(board, commentNumber); + if (c == null) + continue; + hoverComment[commentNumber] = c; + nrToGet[commentNumber] = c.GET; + isComment[commentNumber] = true; + } + else + { + PostData p = await PostsRepository.getPostByGETAsync(board, commentNumber); + if (p == null) + continue; + hoverPost[commentNumber] = p; + nrToGet[commentNumber] = p.GET; + isComment[commentNumber] = false; + } + } + } + } } protected override async Task OnInitializedAsync() @@ -142,6 +213,14 @@ toggleText = opened ? "-" : "+"; } + private string toggleText2 = "-"; + private bool showHover = false; + private void ToggleHovered(MouseEventArgs e, string id) + { + showHover = !showHover; + toggleText2 = showHover ? "-" : "+"; + } + [Parameter] [Required] public CommentData comment { get; set; }