From 0e725b065ad4b291c1575da5569515642fa28d04 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Thu, 2 Feb 2023 22:27:31 +0100 Subject: [PATCH] feat: added Error msgs to post screen, removed second login button. --- ImageBoardServerApp/Pages/Login.razor | 1 - .../Shared/Components/Forms/CommentForm.razor | 25 ++++++++++++++++--- .../Components/Forms/CommentForm.razor.css | 4 +++ .../Shared/Components/Forms/PostForm.razor | 18 +++++++------ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ImageBoardServerApp/Pages/Login.razor b/ImageBoardServerApp/Pages/Login.razor index aad0b5a..3c53718 100644 --- a/ImageBoardServerApp/Pages/Login.razor +++ b/ImageBoardServerApp/Pages/Login.razor @@ -18,7 +18,6 @@ [Login] - diff --git a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor index 509c2f7..0a81474 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor @@ -27,7 +27,10 @@ - + @if (hasErr) + { + @postErr + }
@@ -63,6 +66,9 @@ selectedFile = e.GetMultipleFiles()[0]; this.StateHasChanged(); } + + string postErr { get; set; } + bool hasErr { get; set; } = false; private async Task onPostClick() { @@ -70,9 +76,20 @@ var user = await cauthStateProvder.GetAuthenticationStateAsync(); var usr = user.User; UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name); - int userID = foundusr.UserID; - if(foundusr.TimeBanned != -1) + if (foundusr == null) + { + hasErr = true; + postErr = "You are not logged in."; return; + } + int userID = foundusr.UserID; + if (foundusr.TimeBanned != -1) + { + hasErr = true; + postErr = "You are banned and may not comment."; + //Maybe redirect to /banned? + return; + } foundusr.lastActionTimeStamp = DateTimeOffset.UnixEpoch.ToUnixTimeMilliseconds(); await UsersRepository.updateUserAsync(foundusr); @@ -125,6 +142,8 @@ { //Open comment unsucessfull navigationManager.NavigateTo("/UnSuccessfulPost"); + hasErr = true; + postErr = "There was an error and the comment could not be created. Please notify the admin."; Console.WriteLine("Shit sucks and did not work."); return; } diff --git a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor.css b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor.css index 15998e9..3b0bbb0 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor.css +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor.css @@ -37,4 +37,8 @@ .formContent{ text-align: left; display: flex; +} + +.postError{ + color: #ff191c; } \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index 203fa7d..2389009 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -37,14 +37,13 @@
- -
- - - @if (hasErr) + @if (hasErr) { @postErr } +
+ +
@@ -101,7 +100,9 @@ int userID = foundusr.UserID; if (foundusr.TimeBanned != -1) { - + hasErr = true; + postErr = "You are banned and may not post."; + //Maybe redirect to /banned? return; } foundusr.lastActionTimeStamp = DateTimeOffset.UnixEpoch.ToUnixTimeMilliseconds(); @@ -112,6 +113,8 @@ if (selectedFile == null || selectedFile.Size >= 512000 * 4) { + hasErr = true; + postErr = "You did not attach a file or the selected file is bigger then the 2MiB file limit."; return; } @@ -150,7 +153,8 @@ else { //Open post unsucessfull - NavigationManager.NavigateTo("/UnSuccessfulPost"); + hasErr = true; + postErr = "There was an error and the post could not be created. Please notify the admin."; Console.WriteLine("Shit sucks and did not work."); } }