diff --git a/controllers/threads_controller.go b/controllers/threads_controller.go index 8320e3b..bf22c76 100644 --- a/controllers/threads_controller.go +++ b/controllers/threads_controller.go @@ -244,12 +244,28 @@ func UpdateThread(c *fiber.Ctx) error { // TODO: dat shit crashes if no fields in request text := form.Value["text"][0] filesInRequest := form.File["files"] - validationErrorMessage := utils.ValidatePost("", text, filesInRequest) - if validationErrorMessage != "" { - errorHtmlData := repositories.BadRequestHtmlData{ - Message: validationErrorMessage, + + validationErrors := utils.ValidatePost2("", text, filesInRequest) + if validationErrors != nil { + thread, err := repositories.Posts.GetThreadByPostID(threadID) + if err != nil { + log.Println("error:", err) + return c.Status(fiber.StatusInternalServerError).Render("pages/500", nil) } - return c.Status(fiber.StatusBadRequest).Render("pages/400", errorHtmlData) + + firstPost := thread[0] + captchaID := form.Value["captchaId"][0] + htmlData := repositories.GetThreadHtmlData{ + Thread: thread, + FormData: repositories.HtmlFormData{ + FirstPostID: firstPost.ID, + CaptchaID: captchaID, + IsCaptchaActive: config.App.IsCaptchaActive, + Errors: *validationErrors, + }, + } + + return c.Render("pages/thread", htmlData) } if config.App.IsCaptchaActive { diff --git a/repositories/structs.go b/repositories/structs.go index 121f908..0dd975c 100644 --- a/repositories/structs.go +++ b/repositories/structs.go @@ -39,11 +39,19 @@ type File struct { // HTML Templates Structs // HTML Templates Structs +// post-form.html +type HtmlFormErrors struct { + Title string + Text string + Files string +} + // post-form.html type HtmlFormData struct { FirstPostID int CaptchaID string IsCaptchaActive bool + Errors HtmlFormErrors } // index.html @@ -70,11 +78,11 @@ type BadRequestHtmlData struct { Message string } -const InvalidCaptchaErrorMessage = "INVALID CAPTCHA" -const InvalidTextOrFilesErrorMessage = "TEXT OR FILES SHOULD NOT BE EMPTY" -const InvalidTitleLengthErrorMessage = "TITLE SHOULD NOT EXCEED 100 CHARS" -const InvalidTextLengthErrorMessage = "TEXT SHOULD NOT EXCEED 1000 CHARS" -const InvalidFilesLengthErrorMessage = "MAXIMUM 4 FILES CAN BE UPLOADED" -const InvalidFileSizeErrorMessage = "FILE SIZE EXCIDED (3MB PER FILE)" -const InvalidFileExtErrorMessage = "AVALIABLE FILE EXT: PNG, JPG" -const ThreadIsArchivedErrorMessage = "THREAD IS ARCHIVED" +const InvalidCaptchaErrorMessage = "Invalid captcha" +const InvalidTextOrFilesErrorMessage = "Text or files should not be empty" +const InvalidTitleLengthErrorMessage = "Title should not exceed 100 chars" +const InvalidTextLengthErrorMessage = "Text should not exceed 1000 chars" +const InvalidFilesLengthErrorMessage = "Maximum 4 files can be uploaded" +const InvalidFileSizeErrorMessage = "File size exceeded (3MB PER FILE)" +const InvalidFileExtErrorMessage = "Available file ext: PNG, JPG" +const ThreadIsArchivedErrorMessage = "Thread is archived" diff --git a/static/styles/post-form.css b/static/styles/post-form.css index 1222f54..782d80f 100644 --- a/static/styles/post-form.css +++ b/static/styles/post-form.css @@ -1,3 +1,7 @@ -#postForm > * { +.form-control { margin-bottom: 1rem; +} + +.form-error-label { + color: #f00; } \ No newline at end of file diff --git a/templates/components/post-form.html b/templates/components/post-form.html index 0bde441..78c190d 100644 --- a/templates/components/post-form.html +++ b/templates/components/post-form.html @@ -9,17 +9,20 @@ {{ end }} {{ if eq .FirstPostID 0 }} + {{ end }} + + {{ if .IsCaptchaActive }} {{ template "captcha" .CaptchaID }} {{ end }} -