1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 10:52:55 +08:00

Fix doubled-up enabled state management of commit button

This commit is contained in:
Bartłomiej Dach 2024-09-30 14:05:23 +02:00
parent 155d6e57be
commit 74a9899fc0
No known key found for this signature in database

View File

@ -68,7 +68,7 @@ namespace osu.Game.Overlays.Comments
else else
loadingSpinner.Hide(); loadingSpinner.Hide();
updateCommitButtonState(); updateState();
} }
} }
@ -170,17 +170,15 @@ namespace osu.Game.Overlays.Comments
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Current.BindValueChanged(_ => updateCommitButtonState(), true); Current.BindValueChanged(_ => updateState());
apiState.BindValueChanged(_ => updateEnabledState()); apiState.BindValueChanged(_ => Scheduler.AddOnce(updateState));
CommentableMeta.BindValueChanged(_ => updateEnabledState(), true); CommentableMeta.BindValueChanged(_ => Scheduler.AddOnce(updateState));
updateState();
} }
protected abstract void OnCommit(string text); protected abstract void OnCommit(string text);
private void updateCommitButtonState() => private void updateState()
commitButton.Enabled.Value = loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value);
private void updateEnabledState() => Schedule(() =>
{ {
bool isOnline = apiState.Value > APIState.Offline; bool isOnline = apiState.Value > APIState.Offline;
var canNewCommentReason = CommentEditor.canNewCommentReason(CommentableMeta.Value); var canNewCommentReason = CommentEditor.canNewCommentReason(CommentableMeta.Value);
@ -198,7 +196,7 @@ namespace osu.Game.Overlays.Comments
if (isOnline) if (isOnline)
{ {
commitButton.Show(); commitButton.Show();
commitButton.Enabled.Value = !commentsDisabled; commitButton.Enabled.Value = !commentsDisabled && loadingSpinner.State.Value == Visibility.Hidden && !string.IsNullOrEmpty(Current.Value);
logInButton.Hide(); logInButton.Hide();
} }
else else
@ -206,7 +204,7 @@ namespace osu.Game.Overlays.Comments
commitButton.Hide(); commitButton.Hide();
logInButton.Show(); logInButton.Show();
} }
}); }
// https://github.com/ppy/osu-web/blob/83816dbe24ad2927273cba968f2fcd2694a121a9/resources/js/components/comment-editor.tsx#L54-L60 // https://github.com/ppy/osu-web/blob/83816dbe24ad2927273cba968f2fcd2694a121a9/resources/js/components/comment-editor.tsx#L54-L60
// careful here, logic is VERY finicky. // careful here, logic is VERY finicky.