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
142
ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor
Normal file
142
ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor
Normal file
|
@ -0,0 +1,142 @@
|
|||
@using System.ComponentModel.DataAnnotations
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
|
||||
@inject NavigationManager navigationManager
|
||||
|
||||
<div>
|
||||
<span>[</span>
|
||||
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
|
||||
<span>]</span>
|
||||
</div>
|
||||
@if (opened)
|
||||
{
|
||||
<div class="pd centered">
|
||||
<span>Comment on @post.Title in /@post.Board/</span>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextArea Placeholder="Comment..." @bind-Value="@postContent" Cols="30" Rows="6" Change=@(args => OnChange(args, "Content")) Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
||||
<RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
private bool opened = false;
|
||||
|
||||
private string toggleText = "Open Comment Formula";
|
||||
|
||||
private void ToggleOpened()
|
||||
{
|
||||
opened = !opened;
|
||||
toggleText = opened ? "Close Comment Formula" : "Open Comment Formula";
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public PostData post { get; set; }
|
||||
|
||||
string postUsername = "Anonymous";
|
||||
string postContent = "";
|
||||
|
||||
void OnChange(string value, string name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "username":
|
||||
postUsername = value;
|
||||
if (value == "")
|
||||
{
|
||||
postUsername = "Anonymous";
|
||||
}
|
||||
break;
|
||||
case "content":
|
||||
postContent = value;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("not found.");
|
||||
break;
|
||||
}
|
||||
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 = null;
|
||||
|
||||
private async Task onPostClick()
|
||||
{
|
||||
var userToCreate = new UserData
|
||||
{
|
||||
Ipv4Address = "192.168.178.101",
|
||||
Banned = false,
|
||||
lastActionTimeStamp = DateTime.Now.Millisecond
|
||||
};
|
||||
int userID = await UsersRepository.createUserAsync(userToCreate);
|
||||
|
||||
bool hasImage = image != null;
|
||||
CommentData commentToCreate;
|
||||
if (hasImage)
|
||||
{
|
||||
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()
|
||||
};
|
||||
}
|
||||
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)
|
||||
{
|
||||
//Open comment unsucessfull
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
.toggleOpened{
|
||||
color: #0a58ca;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.toggleOpened:hover{
|
||||
color: #0a58ca; !important;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.centered {
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pd {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.marg{
|
||||
margin: 2px
|
||||
}
|
138
ImageBoardServerApp/Shared/Components/Forms/PostForm.razor
Normal file
138
ImageBoardServerApp/Shared/Components/Forms/PostForm.razor
Normal file
|
@ -0,0 +1,138 @@
|
|||
@using Radzen
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.IO.Pipelines
|
||||
@using System.Net.Mime
|
||||
@using System.Reflection
|
||||
@using System.Runtime.CompilerServices
|
||||
@using ImageBoardServerApp.Data
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<div>
|
||||
<span>[</span>
|
||||
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
|
||||
<span>]</span>
|
||||
</div>
|
||||
@if (opened)
|
||||
{
|
||||
<div class="pd centered">
|
||||
<span>Post to /@board.Tag/ - @board.Topic</span>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextBox Placeholder="Title" MaxLength="20" Change=@(args => OnChange(args, "title")) Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextArea Placeholder="Content..." @bind-Value="@postContent" Cols="30" Rows="6" Change=@(args => OnChange(args, "Content")) Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
||||
<RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
private bool opened = false;
|
||||
|
||||
private string toggleText = "Open Post Formula";
|
||||
|
||||
private void ToggleOpened()
|
||||
{
|
||||
opened = !opened;
|
||||
toggleText = opened ? "Close Post Formula" : "Open Post Formula";
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public BoardData board { get; set; } = new BoardData();
|
||||
|
||||
string postUsername = "Anonymous";
|
||||
string postTitle = "";
|
||||
string postContent = "";
|
||||
|
||||
void OnChange(string value, string name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "title":
|
||||
postTitle = value;
|
||||
break;
|
||||
case "username":
|
||||
postUsername = value;
|
||||
break;
|
||||
case "content":
|
||||
postContent = value;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("not found.");
|
||||
break;
|
||||
}
|
||||
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()
|
||||
{
|
||||
var userToCreate = new UserData
|
||||
{
|
||||
Ipv4Address = "192.168.178.101",
|
||||
Banned = false,
|
||||
lastActionTimeStamp = DateTime.Now.Millisecond
|
||||
};
|
||||
int userID = await UsersRepository.createUserAsync(userToCreate);
|
||||
|
||||
//TODO Add check if data is image
|
||||
|
||||
var imageToUpload = new ImageData
|
||||
{
|
||||
Board = board.Tag,
|
||||
Image = image
|
||||
};
|
||||
int imageID = await ImagesRepository.createImageAsync(imageToUpload);
|
||||
var postToPost = new PostData
|
||||
{
|
||||
UserID = userID,
|
||||
ImageID = imageID,
|
||||
Username = postUsername,
|
||||
Title = postTitle,
|
||||
Content = postContent,
|
||||
Interactions = 0,
|
||||
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
|
||||
Board = board.Tag
|
||||
};
|
||||
int postId = await PostsRepository.createPostAsync(postToPost);
|
||||
if (postId != -1)
|
||||
{
|
||||
//Open post successfull
|
||||
NavigationManager.NavigateTo($"/{board.Tag}/thread/{postId}", true, true);
|
||||
Console.WriteLine("Post created");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Open post unsucessfull
|
||||
NavigationManager.NavigateTo("/UnSuccessfulPost");
|
||||
Console.WriteLine("Shit sucks and did not work.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
.toggleOpened{
|
||||
color: #0a58ca;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.toggleOpened:hover{
|
||||
color: #0a58ca; !important;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.centered {
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pd {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.marg{
|
||||
margin: 2px
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue