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.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 virtual ImageData? Image { get; set; }
public int ImageID { get; set; }
public int? ImageID { get; set; }
[Required]
public string Content { get; set; }

View file

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

View file

@ -1,9 +1,23 @@
@page "/"
@using ImageBoardServerApp.Data.Repository
<h1>BulletBoard</h1>
<div>
This is a simple Imageboard made in Razor.
</div>
<div>
<span>This is a simple Imageboard made in Razor.</span>
<br/>
<span>We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users.</span>
</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 ImageBoardServerApp.Data
@using ImageBoardServerApp.Data.Repository
<div class="threadHeader">
<span>[</span>
@ -13,25 +14,28 @@
{
<div class="threadContent">
<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" />
}
else
{
<span>[No Image]</span>
<img src="@($"data:image/jpeg;base64,{Convert.ToBase64String(image.Image)}")" alt="No Image found" />
}
</div>
<div class="threadTextContainer">
@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 class="threadFooter">
<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>
</div>
}
@ -46,6 +50,25 @@
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 string toggleText = "-";

View file

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

View file

@ -1,7 +1,7 @@
@using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data.Repository
@inject NavigationManager NavigationManager
@inject NavigationManager navigationManager
<div>
<span>[</span>
@ -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
@ -138,11 +130,13 @@
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;
}
}

View file

@ -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

View file

@ -29,7 +29,14 @@
<div class="threadTextContainer">
@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>
@ -41,7 +48,7 @@
@if (showOpenThread)
{
<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>
}
else

View file

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

View file

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