finished implementing thread view, finished adding comments

This commit is contained in:
limited_dev 2023-01-26 13:04:55 +01:00
parent f09722757a
commit 3e7218c6ae
12 changed files with 87 additions and 34 deletions

View file

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using ImageBoardServerApp.Shared.Components; using ImageBoardServerApp.Shared.Components;
namespace ImageBoardServerApp.Data; namespace ImageBoardServerApp.Data;
@ -24,9 +25,9 @@ public class CommentData
public virtual UserData User { get; set; } public virtual UserData User { get; set; }
//[ForeignKey("ImageID")] //[ForeignKey("ImageID")]
public virtual ImageData Image { get; set; } public virtual ImageData? Image { get; set; }
public int ImageID { get; set; } public int? ImageID { get; set; }
[Required] [Required]
public string Content { get; set; } public string Content { get; set; }

View file

@ -22,4 +22,9 @@
<Folder Include="wwwroot\static" /> <Folder Include="wwwroot\static" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Shared\Components\Forms\CommentForm.razor" />
<AdditionalFiles Include="Shared\Components\Forms\PostForm.razor" />
</ItemGroup>
</Project> </Project>

View file

@ -1,9 +1,23 @@
@page "/" @page "/"
@using ImageBoardServerApp.Data.Repository
<h1>BulletBoard</h1> <h1>BulletBoard</h1>
<div> <span>This is a simple Imageboard made in Razor.</span>
This is a simple Imageboard made in Razor. <br/>
</div> <span>We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users.</span>
<div>
</div> @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;
}
}

View file

@ -1,5 +1,6 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data @using ImageBoardServerApp.Data
@using ImageBoardServerApp.Data.Repository
<div class="threadHeader"> <div class="threadHeader">
<span>[</span> <span>[</span>
@ -13,25 +14,28 @@
{ {
<div class="threadContent"> <div class="threadContent">
<div class="threadImage"> <div class="threadImage">
@if (@comment.Image != null) @if (image != null)
{ {
<img src="@($"data:image/jpeg;base64,{Convert.ToBase64String(@comment.Image.Image)}")" alt="No Image found" /> <img src="@($"data:image/jpeg;base64,{Convert.ToBase64String(image.Image)}")" alt="No Image found" />
}
else
{
<span>[No Image]</span>
} }
</div> </div>
<div class="threadTextContainer"> <div class="threadTextContainer">
@foreach (string s in @comment.Content.Split("\n")) @foreach (string s in @comment.Content.Split("\n"))
{ {
<span class='threadText'>@s</span> @if (s.StartsWith(">"))
{
<span class="threadText greenText">@s</span>
}
else
{
<span class='threadText'>@s</span>
}
} }
</div> </div>
</div> </div>
<div class="threadFooter"> <div class="threadFooter">
<span>[</span> <span>[</span>
<a class="report" href="/report/@comment.Board/@comment.CommentID" target="_blank">Report</a> <a class="report" href="/report/@comment.Board/@comment.PostID/comment/@comment.CommentID" target="_blank">Report</a>
<span>]</span> <span>]</span>
</div> </div>
} }
@ -46,6 +50,25 @@
return dateTime; 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; private bool opened = true;
private string toggleText = "-"; private string toggleText = "-";

View file

@ -30,6 +30,10 @@
display: flex; display: flex;
} }
.greenText{
color: #3caf03;
}
.threadImage{ .threadImage{
margin: 6px; margin: 6px;
max-width: 500px; max-width: 500px;

View file

@ -1,7 +1,7 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data.Repository @using ImageBoardServerApp.Data.Repository
@inject NavigationManager NavigationManager @inject NavigationManager navigationManager
<div> <div>
<span>[</span> <span>[</span>
@ -80,7 +80,7 @@
ms.Close(); ms.Close();
} }
private Byte[] image; private Byte[] image = null;
private async Task onPostClick() private async Task onPostClick()
{ {
@ -92,7 +92,7 @@
}; };
int userID = await UsersRepository.createUserAsync(userToCreate); int userID = await UsersRepository.createUserAsync(userToCreate);
bool hasImage = false; bool hasImage = image != null;
CommentData commentToCreate; CommentData commentToCreate;
if (hasImage) if (hasImage)
{ {
@ -111,14 +111,6 @@
Username = postUsername, Username = postUsername,
Board = post.Board, Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds()
/*
UserID = userID,
Post = post,
Username = postUsername,
Content = postContent,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
Board = post.Board
*/
}; };
} }
else else
@ -138,11 +130,13 @@
if (commentId == -1) if (commentId == -1)
{ {
//Open comment unsucessfull //Open comment unsucessfull
NavigationManager.NavigateTo("/UnSuccessfulPost"); navigationManager.NavigateTo("/UnSuccessfulPost");
Console.WriteLine("Shit sucks and did not work."); Console.WriteLine("Shit sucks and did not work.");
return; return;
} }
//comment successfull //comment successfull
Console.WriteLine("Post created"); Console.WriteLine("Post created");
navigationManager.NavigateTo($"/{post.Board}/thread/{post.PostID}", true, true);
opened = false;
} }
} }

View file

@ -125,7 +125,7 @@
if (postId != -1) if (postId != -1)
{ {
//Open post successfull //Open post successfull
NavigationManager.NavigateTo("/SuccessfulPost"); NavigationManager.NavigateTo($"/{board.Tag}/thread/{postId}", true, true);
Console.WriteLine("Post created"); Console.WriteLine("Post created");
} }
else else

View file

@ -29,7 +29,14 @@
<div class="threadTextContainer"> <div class="threadTextContainer">
@foreach (string s in @post.Content.Split("\n")) @foreach (string s in @post.Content.Split("\n"))
{ {
<span class='threadText'>@s</span> @if (s.StartsWith(">"))
{
<span class="threadText greenText">@s</span>
}
else
{
<span class='threadText'>@s</span>
}
} }
</div> </div>
</div> </div>
@ -41,7 +48,7 @@
@if (showOpenThread) @if (showOpenThread)
{ {
<span>[</span> <span>[</span>
<a class="openThread" href="/@post.Board/thread/@post.PostID" target="_blank">(@post.Comments.Count) Open Thread</a> <a class="openThread" href="/@post.Board/thread/@post.PostID">(@post.Comments.Count) Open Thread</a>
<span>]</span> <span>]</span>
} }
else else

View file

@ -30,6 +30,10 @@
display: flex; display: flex;
} }
.greenText{
color: #3caf03;
}
.threadImage{ .threadImage{
margin: 6px; margin: 6px;
max-width: 500px; max-width: 500px;

View file

@ -13,4 +13,5 @@
@using ImageBoardServerApp @using ImageBoardServerApp
@using ImageBoardServerApp.Shared @using ImageBoardServerApp.Shared
@using ImageBoardServerApp.Shared.Components @using ImageBoardServerApp.Shared.Components
@using ImageBoardServerApp.Shared.Components.Forms
@using ImageBoardServerApp.Data @using ImageBoardServerApp.Data