finished implementing thread view, finished adding comments
This commit is contained in:
parent
f09722757a
commit
3e7218c6ae
12 changed files with 87 additions and 34 deletions
|
@ -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; }
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
@page "/"
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
|
||||
<h1>BulletBoard</h1>
|
||||
<div>
|
||||
This is a simple Imageboard made in Razor.
|
||||
</div>
|
||||
<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>
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
display: flex;
|
||||
}
|
||||
|
||||
.greenText{
|
||||
color: #3caf03;
|
||||
}
|
||||
|
||||
.threadImage{
|
||||
margin: 6px;
|
||||
max-width: 500px;
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
display: flex;
|
||||
}
|
||||
|
||||
.greenText{
|
||||
color: #3caf03;
|
||||
}
|
||||
|
||||
.threadImage{
|
||||
margin: 6px;
|
||||
max-width: 500px;
|
||||
|
|
|
@ -13,4 +13,5 @@
|
|||
@using ImageBoardServerApp
|
||||
@using ImageBoardServerApp.Shared
|
||||
@using ImageBoardServerApp.Shared.Components
|
||||
@using ImageBoardServerApp.Data
|
||||
@using ImageBoardServerApp.Shared.Components.Forms
|
||||
@using ImageBoardServerApp.Data
|
||||
|
|
Loading…
Reference in a new issue