feat: it is now possible to not show the admin tag when posting, fixed the delete button not showing up

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-13 08:51:53 +02:00
parent 9bb208d011
commit 9d733af389
5 changed files with 33 additions and 31 deletions

View file

@ -10,10 +10,11 @@
<a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a> <a class="toggleOpened" onclick="@ToggleOpened">@toggleText</a>
<span>]</span> <span>]</span>
<span class="name">@comment.Username</span> <span class="name">@comment.Username</span>
@if (@role != "User") @if (@role != "User" && !comment.shouldAnon)
{ {
<span class="@role">##@role</span> <span class="@role">##@role</span>
} }
<span>&nbsp;</span>
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span> <span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
<span class="post-id">No.@comment.GET</span> <span class="post-id">No.@comment.GET</span>
</div> </div>
@ -149,7 +150,6 @@
{ {
await base.OnParametersSetAsync(); await base.OnParametersSetAsync();
hoverComment = new Dictionary<int, CommentData>(); hoverComment = new Dictionary<int, CommentData>();
hoverPost = new Dictionary<int, PostData>(); hoverPost = new Dictionary<int, PostData>();
nrToGet = new Dictionary<int, int>(); nrToGet = new Dictionary<int, int>();
@ -185,10 +185,6 @@
} }
} }
reportURL = $"/sys/report/comment/{comment.Board}/{comment.CommentID}"; reportURL = $"/sys/report/comment/{comment.Board}/{comment.CommentID}";
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
var user = await cauthStateProvder.GetAuthenticationStateAsync(); var user = await cauthStateProvder.GetAuthenticationStateAsync();
var usr = user.User; var usr = user.User;
@ -201,9 +197,9 @@
{ {
canDel = false; canDel = false;
} }
await base.OnAfterRenderAsync(firstRender);
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
int i; int i;

View file

@ -4,13 +4,13 @@
<div class="comment"> <div class="comment">
<span class="name">@comment.Username</span> <span class="name">@comment.Username</span>
@if (@role != "User") @if (@role != "User" && !comment.shouldAnon)
{ {
<span class="@role">##@role </span> <span class="@role">##@role&nbsp;</span>
} }
else else
{ {
<span> </span> <span>&nbsp;</span>
} }
<span class="date">@getTimeFromUnix(comment.CreatedAt)</span> <span class="date">@getTimeFromUnix(comment.CreatedAt)</span>
<span class="post-id">No.@comment.GET</span> <span class="post-id">No.@comment.GET</span>

View file

@ -24,6 +24,12 @@
<div class="pd centered marg"> <div class="pd centered marg">
<RadzenTextArea Placeholder="Comment..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/> <RadzenTextArea Placeholder="Comment..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/>
</div> </div>
<AuthorizeView Roles="Admin,Mod">
<Authorized>
<RadzenCheckBox @bind-Value=@postAnon Name="postAsAnon"/>
<RadzenLabel Text="Do not show role." Component="postAsAnon"/>
</Authorized>
</AuthorizeView>
</div> </div>
</div> </div>
@if (hasErr) @if (hasErr)
@ -57,6 +63,7 @@
string postUsername { get; set; } string postUsername { get; set; }
string postContent { get; set; } = ""; string postContent { get; set; } = "";
bool postAnon { get; set; } = false;
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
@ -164,7 +171,8 @@
Username = postUsername, Username = postUsername,
Board = post.Board, Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(), CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
GET = thisGET GET = thisGET,
shouldAnon = postAnon
}; };
} }
else else
@ -177,7 +185,8 @@
Username = postUsername, Username = postUsername,
Board = post.Board, Board = post.Board,
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(), CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
GET = thisGET GET = thisGET,
shouldAnon = postAnon
}; };
} }

View file

@ -28,6 +28,12 @@
<div class="pd centered marg"> <div class="pd centered marg">
<RadzenTextArea Placeholder="Content..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/> <RadzenTextArea Placeholder="Content..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/>
</div> </div>
<AuthorizeView Roles="Admin,Mod">
<Authorized>
<RadzenCheckBox @bind-Value=@postAnon Name="postAsAnon"/>
<RadzenLabel Text="Do not show role." Component="postAsAnon"/>
</Authorized>
</AuthorizeView>
</div> </div>
</div> </div>
@if (hasErr) @if (hasErr)
@ -63,6 +69,7 @@
string postUsername { get; set; } string postUsername { get; set; }
string postTitle { get; set; } = ""; string postTitle { get; set; } = "";
string postContent { get; set; } = ""; string postContent { get; set; } = "";
bool postAnon { get; set; } = false;
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
@ -175,7 +182,8 @@
Board = board.Tag, Board = board.Tag,
IsLocked = false, IsLocked = false,
IsSticky = false, IsSticky = false,
GET = thisGET GET = thisGET,
shouldAnon = postAnon
}; };
int postId = await PostsRepository.createPostAsync(postToPost); int postId = await PostsRepository.createPostAsync(postToPost);
if (postId != -1) if (postId != -1)

View file

@ -17,11 +17,11 @@
} }
<span class="title">@post.Title</span> <span class="title">@post.Title</span>
<span class="name">@post.Username </span> <span class="name">@post.Username </span>
@if (post.User.Role != "User") @if (post.User.Role != "User" && !post.shouldAnon)
{ {
<span class="@post.User.Role">##@post.User.Role </span> <span class="@post.User.Role">##@post.User.Role&nbsp;</span>
} }
<span> </span> <span>&nbsp;</span>
<span class="date"> @getTimeFromUnix(post.CreatedAt)</span> <span class="date"> @getTimeFromUnix(post.CreatedAt)</span>
<span class="post-id">No.@post.GET</span> <span class="post-id">No.@post.GET</span>
@if (post.IsSticky) @if (post.IsSticky)
@ -202,8 +202,6 @@
toggleText = opened ? "-" : "+"; toggleText = opened ? "-" : "+";
} }
private int usrid { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
value = TheManager.getBumpValue(post) + "v"; value = TheManager.getBumpValue(post) + "v";
@ -212,25 +210,16 @@
threadURL = $"/{post.Board}/thread/{post.PostID}"; threadURL = $"/{post.Board}/thread/{post.PostID}";
openThreadName = $"({post.Comments.Count}) View Thread"; openThreadName = $"({post.Comments.Count}) View Thread";
await base.OnInitializedAsync();
}
public override async Task SetParametersAsync(ParameterView parameters)
{
if (usrid == null)
{
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
var user = await cauthStateProvder.GetAuthenticationStateAsync(); var user = await cauthStateProvder.GetAuthenticationStateAsync();
usrid = int.Parse(user.User.Identity.Name); UserData foundusr = await UsersRepository.getUserByEmailRawAsync(user.User.Identity.Name);
}
UserData foundusr = await UsersRepository.getUserByIdAsync(usrid);
if (foundusr != null && (foundusr.Role != "User" || post.UserID == foundusr.UserID)) if (foundusr != null && (foundusr.Role != "User" || post.UserID == foundusr.UserID))
{ {
canDel = true; canDel = true;
return; return;
} }
canDel = false; canDel = false;
await base.SetParametersAsync(parameters); await base.OnInitializedAsync();
} }