mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 19:04:05 +02:00
Fix page count increasing when refreshing comments, disable "Submit" button until comments are refreshed
This commit is contained in:
@@ -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()
|
||||
|
@@ -35,6 +35,7 @@ public:
|
||||
|
||||
bool NextCommentPage();
|
||||
bool PrevCommentPage();
|
||||
void RefreshComments();
|
||||
void CommentAdded();
|
||||
|
||||
virtual ~PreviewController();
|
||||
|
@@ -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<http::AddCommentRequest>(c->SaveID(), comment);
|
||||
addCommentRequest->Start();
|
||||
|
||||
CheckComment();
|
||||
}
|
||||
|
||||
submitCommentButton->Enabled = false;
|
||||
FocusComponent(NULL);
|
||||
|
||||
addCommentRequest = std::make_unique<http::AddCommentRequest>(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;
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user