diff --git a/ImageBoardServerApp/Data/CommentData.cs b/ImageBoardServerApp/Data/CommentData.cs index 782450c..bcaf8a1 100644 --- a/ImageBoardServerApp/Data/CommentData.cs +++ b/ImageBoardServerApp/Data/CommentData.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics.CodeAnalysis; using ImageBoardServerApp.Shared.Components; namespace ImageBoardServerApp.Data; @@ -24,9 +25,9 @@ public class CommentData public virtual UserData User { get; set; } //[ForeignKey("ImageID")] - public virtual ImageData Image { get; set; } - - public int ImageID { get; set; } + public virtual ImageData? Image { get; set; } + + public int? ImageID { get; set; } [Required] public string Content { get; set; } diff --git a/ImageBoardServerApp/ImageBoardServerApp.csproj b/ImageBoardServerApp/ImageBoardServerApp.csproj index ef2c7bc..4dda036 100644 --- a/ImageBoardServerApp/ImageBoardServerApp.csproj +++ b/ImageBoardServerApp/ImageBoardServerApp.csproj @@ -22,4 +22,9 @@ + + + + + diff --git a/ImageBoardServerApp/Pages/Index.razor b/ImageBoardServerApp/Pages/Index.razor index 292616f..e3fd3ad 100644 --- a/ImageBoardServerApp/Pages/Index.razor +++ b/ImageBoardServerApp/Pages/Index.razor @@ -1,9 +1,23 @@ @page "/" +@using ImageBoardServerApp.Data.Repository

BulletBoard

-
- This is a simple Imageboard made in Razor. -
-
- -
\ No newline at end of file +This is a simple Imageboard made in Razor. +
+We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users. + +@code{ + private int amountOfPosts = -1; + private int amountOfComments = -1; + private int amountOfUsers = -1; + protected override async Task OnInitializedAsync() + { + var posts = await PostsRepository.getPostsAsync(); + amountOfPosts = posts.Count; + var comments = await CommentsRepository.getCommentsAsync(); + amountOfComments = comments.Count; + var users = await UsersRepository.getUsersAsync(); + amountOfUsers = users.Count; + } + +} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor b/ImageBoardServerApp/Shared/Components/Comment.razor index 2bf523c..8b54619 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor +++ b/ImageBoardServerApp/Shared/Components/Comment.razor @@ -1,5 +1,6 @@ @using System.ComponentModel.DataAnnotations @using ImageBoardServerApp.Data +@using ImageBoardServerApp.Data.Repository
[ @@ -13,25 +14,28 @@ {
- @if (@comment.Image != null) + @if (image != null) { - No Image found - } - else - { - [No Image] + No Image found }
@foreach (string s in @comment.Content.Split("\n")) { - @s + @if (s.StartsWith(">")) + { + @s + } + else + { + @s + } }
[ - Report + Report ]
} @@ -45,6 +49,25 @@ dateTime = dateTime.AddMilliseconds( javaTimeStamp ).ToLocalTime(); return dateTime; } + + private ImageData image; + + protected override async Task OnInitializedAsync() + { + int i; + try + { + i = (int)comment.ImageID; + } + catch (InvalidOperationException ioe) + { + i = -1; + } + if (i != null) + { + image = await ImagesRepository.getImageByIdAsync(i); + } + } private bool opened = true; diff --git a/ImageBoardServerApp/Shared/Components/Comment.razor.css b/ImageBoardServerApp/Shared/Components/Comment.razor.css index da7824a..b78f7fa 100644 --- a/ImageBoardServerApp/Shared/Components/Comment.razor.css +++ b/ImageBoardServerApp/Shared/Components/Comment.razor.css @@ -30,6 +30,10 @@ display: flex; } +.greenText{ + color: #3caf03; +} + .threadImage{ margin: 6px; max-width: 500px; diff --git a/ImageBoardServerApp/Shared/Components/CommentForm.razor b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor similarity index 90% rename from ImageBoardServerApp/Shared/Components/CommentForm.razor rename to ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor index bd7fb8e..1cf580a 100644 --- a/ImageBoardServerApp/Shared/Components/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor @@ -1,7 +1,7 @@ @using System.ComponentModel.DataAnnotations @using ImageBoardServerApp.Data.Repository -@inject NavigationManager NavigationManager +@inject NavigationManager navigationManager
[ @@ -80,7 +80,7 @@ ms.Close(); } - private Byte[] image; + private Byte[] image = null; private async Task onPostClick() { @@ -92,7 +92,7 @@ }; int userID = await UsersRepository.createUserAsync(userToCreate); - bool hasImage = false; + bool hasImage = image != null; CommentData commentToCreate; if (hasImage) { @@ -111,14 +111,6 @@ 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 @@ -133,16 +125,18 @@ CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() }; } - + int commentId = await CommentsRepository.createCommentAsync(commentToCreate); if (commentId == -1) { //Open comment unsucessfull - NavigationManager.NavigateTo("/UnSuccessfulPost"); + navigationManager.NavigateTo("/UnSuccessfulPost"); Console.WriteLine("Shit sucks and did not work."); return; } //comment successfull Console.WriteLine("Post created"); + navigationManager.NavigateTo($"/{post.Board}/thread/{post.PostID}", true, true); + opened = false; } } \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/CommentForm.razor.css b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor.css similarity index 100% rename from ImageBoardServerApp/Shared/Components/CommentForm.razor.css rename to ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor.css diff --git a/ImageBoardServerApp/Shared/Components/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor similarity index 97% rename from ImageBoardServerApp/Shared/Components/PostForm.razor rename to ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index 166423b..ff8af17 100644 --- a/ImageBoardServerApp/Shared/Components/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -125,7 +125,7 @@ if (postId != -1) { //Open post successfull - NavigationManager.NavigateTo("/SuccessfulPost"); + NavigationManager.NavigateTo($"/{board.Tag}/thread/{postId}", true, true); Console.WriteLine("Post created"); } else diff --git a/ImageBoardServerApp/Shared/Components/PostForm.razor.css b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor.css similarity index 100% rename from ImageBoardServerApp/Shared/Components/PostForm.razor.css rename to ImageBoardServerApp/Shared/Components/Forms/PostForm.razor.css diff --git a/ImageBoardServerApp/Shared/Components/Post.razor b/ImageBoardServerApp/Shared/Components/Post.razor index 2c08a0a..767c087 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor +++ b/ImageBoardServerApp/Shared/Components/Post.razor @@ -29,7 +29,14 @@
@foreach (string s in @post.Content.Split("\n")) { - @s + @if (s.StartsWith(">")) + { + @s + } + else + { + @s + } }
@@ -41,7 +48,7 @@ @if (showOpenThread) { [ - (@post.Comments.Count) Open Thread + (@post.Comments.Count) Open Thread ] } else diff --git a/ImageBoardServerApp/Shared/Components/Post.razor.css b/ImageBoardServerApp/Shared/Components/Post.razor.css index da7824a..b78f7fa 100644 --- a/ImageBoardServerApp/Shared/Components/Post.razor.css +++ b/ImageBoardServerApp/Shared/Components/Post.razor.css @@ -30,6 +30,10 @@ display: flex; } +.greenText{ + color: #3caf03; +} + .threadImage{ margin: 6px; max-width: 500px; diff --git a/ImageBoardServerApp/_Imports.razor b/ImageBoardServerApp/_Imports.razor index a2e21d4..5b43e85 100644 --- a/ImageBoardServerApp/_Imports.razor +++ b/ImageBoardServerApp/_Imports.razor @@ -13,4 +13,5 @@ @using ImageBoardServerApp @using ImageBoardServerApp.Shared @using ImageBoardServerApp.Shared.Components -@using ImageBoardServerApp.Data \ No newline at end of file +@using ImageBoardServerApp.Shared.Components.Forms +@using ImageBoardServerApp.Data