diff --git a/src/gui/preview/PreviewController.cpp b/src/gui/preview/PreviewController.cpp index 5325515e4..941f4606d 100644 --- a/src/gui/preview/PreviewController.cpp +++ b/src/gui/preview/PreviewController.cpp @@ -126,10 +126,15 @@ bool PreviewController::PrevCommentPage() return false; } +void PreviewController::RefreshComments() +{ + previewModel->UpdateComments(1); +} + void PreviewController::CommentAdded() { previewModel->CommentAdded(); - previewModel->UpdateComments(1); + RefreshComments(); } void PreviewController::Exit() diff --git a/src/gui/preview/PreviewController.h b/src/gui/preview/PreviewController.h index c9adeaafb..fb9dcd52e 100644 --- a/src/gui/preview/PreviewController.h +++ b/src/gui/preview/PreviewController.h @@ -35,6 +35,7 @@ public: bool NextCommentPage(); bool PrevCommentPage(); + void RefreshComments(); void CommentAdded(); virtual ~PreviewController(); diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 66d237a34..e66c7ca26 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -435,7 +435,8 @@ void PreviewView::OnTick(float dt) { new ErrorMessage("Error submitting comment", ByteString(ex.what()).FromUtf8()); } - submitCommentButton->Enabled = true; + isSubmittingComment = false; + CheckCommentSubmitEnabled(); commentBoxAutoHeight(); addCommentRequest.reset(); CheckComment(); @@ -603,25 +604,34 @@ void PreviewView::submitComment() String comment = addCommentBox->GetText(); if (comment.length() == 0) { - c->CommentAdded(); - return; + c->RefreshComments(); + isRefreshingComments = true; } - if (comment.length() < 4) + else if (comment.length() < 4) { new ErrorMessage("Error", "Comment is too short"); - return; + } + else + { + isSubmittingComment = true; + FocusComponent(NULL); + + addCommentRequest = std::make_unique(c->SaveID(), comment); + addCommentRequest->Start(); + + CheckComment(); } - submitCommentButton->Enabled = false; - FocusComponent(NULL); - - addCommentRequest = std::make_unique(c->SaveID(), comment); - addCommentRequest->Start(); - - CheckComment(); + CheckCommentSubmitEnabled(); } } +void PreviewView::CheckCommentSubmitEnabled() +{ + if (submitCommentButton) + submitCommentButton->Enabled = !isRefreshingComments && !isSubmittingComment; +} + void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) { if(addCommentBox) @@ -654,7 +664,6 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) AddComponent(addCommentBox); submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit"); submitCommentButton->SetActionCallback({ [this] { submitComment(); } }); - //submitCommentButton->Enabled = false; AddComponent(submitCommentButton); commentWarningLabel = new ui::Label(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 16), "If you see this it is a bug"); @@ -696,6 +705,9 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender) commentTextComponents.clear(); commentsPanel->InnerSize = ui::Point(0, 0); + isRefreshingComments = false; + CheckCommentSubmitEnabled(); + if (commentsPtr) { auto &comments = *commentsPtr; diff --git a/src/gui/preview/PreviewView.h b/src/gui/preview/PreviewView.h index e01a09163..69df17287 100644 --- a/src/gui/preview/PreviewView.h +++ b/src/gui/preview/PreviewView.h @@ -59,6 +59,8 @@ class PreviewView: public ui::Window String doErrorMessage; bool showAvatars; bool prevPage; + bool isSubmittingComment = false; + bool isRefreshingComments = false; int commentBoxHeight; float commentBoxPositionX; @@ -72,6 +74,7 @@ class PreviewView: public ui::Window void displayComments(); void commentBoxAutoHeight(); void submitComment(); + void CheckCommentSubmitEnabled(); bool CheckSwearing(String text); void CheckComment(); void ShowMissingCustomElements();