bulletboards/ImageBoardServerApp/Pages/Basic/ThreadPage.razor
limited_dev 508510962a fix: Page no longer Errors when accessing a nonexistent thread
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
2023-06-13 07:42:48 +02:00

48 lines
No EOL
1.1 KiB
Text

@page "/{boardName}/thread/{threadId}"
@using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data.Repository
@inject NavigationManager NavigationManager
<PageTitle>Thread #@post.GET on /@boardName/ - BulletBoard</PageTitle>
<h3>Thread #@post.GET on /@boardName/</h3>
<Post post="@post" showOpenThread="false"/>
<hr/>
@foreach (var comment in post.Comments)
{
<Comment comment="comment"/>
<hr/>
}
<div class="Form">
<CommentForm post="post"/>
</div>
@code {
[Parameter]
[Required]
public string boardName { get; set; }
[Parameter]
[Required]
public string threadId { get; set; }
private PostData post;
protected override async Task OnInitializedAsync()
{
if (!int.TryParse(threadId, out _))
NavigationManager.NavigateTo("/notfound");
post = await PostsRepository.getPostByIdAsync(int.Parse(threadId));
if (post == null)
NavigationManager.NavigateTo("/notfound");
if (post.Board != boardName)
NavigationManager.NavigateTo("/notfound");
if (post == null)
NavigationManager.NavigateTo("/notfound");
}
}