From f09722757aa126a3609b457f4a447aeaf19e9bdb Mon Sep 17 00:00:00 2001 From: limited_dev Date: Thu, 26 Jan 2023 09:07:25 +0100 Subject: [PATCH] continued to work in comments --- ImageBoardServerApp/Data/CommentData.cs | 2 +- ImageBoardServerApp/Pages/ThreadPage.razor | 2 + .../Shared/Components/CommentForm.razor | 60 +++++++++++++++---- .../Shared/Components/PostForm.razor | 1 - 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/ImageBoardServerApp/Data/CommentData.cs b/ImageBoardServerApp/Data/CommentData.cs index bfc5e5d..782450c 100644 --- a/ImageBoardServerApp/Data/CommentData.cs +++ b/ImageBoardServerApp/Data/CommentData.cs @@ -21,7 +21,7 @@ public class CommentData public int UserID { get; set; } //[ForeignKey("UserID")] - public UserData User { get; set; } + public virtual UserData User { get; set; } //[ForeignKey("ImageID")] public virtual ImageData Image { get; set; } diff --git a/ImageBoardServerApp/Pages/ThreadPage.razor b/ImageBoardServerApp/Pages/ThreadPage.razor index a2349e7..d6c3dfc 100644 --- a/ImageBoardServerApp/Pages/ThreadPage.razor +++ b/ImageBoardServerApp/Pages/ThreadPage.razor @@ -36,6 +36,8 @@ NavigationManager.NavigateTo("/notfound"); return; } + if(post.Board != boardName) + NavigationManager.NavigateTo("/notfound"); if(post == null) NavigationManager.NavigateTo("/notfound"); } diff --git a/ImageBoardServerApp/Shared/Components/CommentForm.razor b/ImageBoardServerApp/Shared/Components/CommentForm.razor index c654871..bd7fb8e 100644 --- a/ImageBoardServerApp/Shared/Components/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/CommentForm.razor @@ -11,7 +11,7 @@ @if (opened) {
- Comment on @post.Title by @post.Username in @post.Board + Comment on @post.Title in /@post.Board/
OnChange(args, "username")) Class="w-100"/> @@ -22,6 +22,7 @@
+
@@ -68,6 +69,18 @@ } Console.WriteLine($"Smth changed!: {value}"); } + + private async Task SingleUpload(InputFileChangeEventArgs e) + { + MemoryStream ms = new MemoryStream(); + await e.File.OpenReadStream().CopyToAsync(ms); + var bytes = ms.ToArray(); + image = bytes; + Console.WriteLine("File has been selected!"); + ms.Close(); + } + + private Byte[] image; private async Task onPostClick() { @@ -78,24 +91,49 @@ lastActionTimeStamp = DateTime.Now.Millisecond }; int userID = await UsersRepository.createUserAsync(userToCreate); - - var commentToCreate = new CommentData() + + bool hasImage = false; + CommentData commentToCreate; + if (hasImage) { - PostID = post.PostID, + var imageToUpload = new ImageData + { + Board = post.Board, + Image = image + }; + int imageID = await ImagesRepository.createImageAsync(imageToUpload); + commentToCreate = new CommentData() + { + PostID = post.PostID, + UserID = userID, + ImageID = imageID, + Content = postContent, + Username = postUsername, + Board = post.Board, + CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() + /* UserID = userID, - Content = postContent, - Username = postUsername, - Board = post.Board, - CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() - /* - * UserID = userID, Post = post, Username = postUsername, Content = postContent, CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(), Board = post.Board */ - }; + }; + } + else + { + commentToCreate = new CommentData() + { + PostID = post.PostID, + UserID = userID, + Content = postContent, + Username = postUsername, + Board = post.Board, + CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() + }; + } + int commentId = await CommentsRepository.createCommentAsync(commentToCreate); if (commentId == -1) { diff --git a/ImageBoardServerApp/Shared/Components/PostForm.razor b/ImageBoardServerApp/Shared/Components/PostForm.razor index da4f66e..166423b 100644 --- a/ImageBoardServerApp/Shared/Components/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/PostForm.razor @@ -103,7 +103,6 @@ int userID = await UsersRepository.createUserAsync(userToCreate); //TODO Add check if data is image - var imageToUpload = new ImageData {