mirror of
https://github.com/ppy/osu.git
synced 2026-05-18 23:10:50 +08:00
Merge pull request #34410 from bdach/favourite-fail
Fix song select favourite button getting stuck spinning if operation failed
This commit is contained in:
@@ -18,6 +18,7 @@ using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Beatmaps.Drawables;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
@@ -246,6 +247,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
{
|
||||
var (working, onlineSet) = createTestBeatmap();
|
||||
onlineSet.FavouriteCount = 9999;
|
||||
onlineSet.HasFavourited = true;
|
||||
working.BeatmapSetInfo.OnlineID = onlineSet.OnlineID = 99999;
|
||||
|
||||
currentOnlineSet = onlineSet;
|
||||
@@ -253,6 +255,42 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
});
|
||||
AddStep("allow request to complete", () => resetEvent.Set());
|
||||
AddAssert("favourites count = 9999", () => this.ChildrenOfType<BeatmapTitleWedge.FavouriteButton>().Single().Text.ToString() == "9,999");
|
||||
|
||||
AddStep("set up request handler to fail", () =>
|
||||
{
|
||||
((DummyAPIAccess)API).HandleRequest = request =>
|
||||
{
|
||||
switch (request)
|
||||
{
|
||||
case GetBeatmapSetRequest set:
|
||||
if (set.ID == currentOnlineSet?.OnlineID)
|
||||
{
|
||||
set.TriggerSuccess(currentOnlineSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
case PostBeatmapFavouriteRequest favourite:
|
||||
Task.Run(() =>
|
||||
{
|
||||
resetEvent.Wait(10000);
|
||||
favourite.TriggerFailure(new APIException("You have too many favourited beatmaps! Please unfavourite some before trying again.", null));
|
||||
});
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
});
|
||||
AddStep("reset event", () => resetEvent.Reset());
|
||||
AddStep("click favourite button", () => this.ChildrenOfType<BeatmapTitleWedge.FavouriteButton>().Single().TriggerClick());
|
||||
AddAssert("spinner visible", () => this.ChildrenOfType<BeatmapTitleWedge.FavouriteButton>().Single()
|
||||
.ChildrenOfType<LoadingSpinner>().Single().State.Value, () => Is.EqualTo(Visibility.Visible));
|
||||
AddStep("allow request to complete", () => resetEvent.Set());
|
||||
AddAssert("spinner hidden", () => this.ChildrenOfType<BeatmapTitleWedge.FavouriteButton>().Single()
|
||||
.ChildrenOfType<LoadingSpinner>().Single().State.Value, () => Is.EqualTo(Visibility.Hidden));
|
||||
}
|
||||
|
||||
[TestCase(120, 125, null, "120-125 (mostly 120)")]
|
||||
|
||||
@@ -21,6 +21,7 @@ using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@@ -50,6 +51,9 @@ namespace osu.Game.Screens.SelectV2
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private INotificationOverlay? notifications { get; set; }
|
||||
|
||||
internal LocalisableString Text => valueText.Text;
|
||||
|
||||
public FavouriteButton()
|
||||
@@ -224,6 +228,15 @@ namespace osu.Game.Screens.SelectV2
|
||||
beatmapSet.FavouriteCount += hasFavourited ? 1 : -1;
|
||||
setBeatmapSet(beatmapSet, withHeartAnimation: hasFavourited);
|
||||
};
|
||||
favouriteRequest.Failure += e =>
|
||||
{
|
||||
notifications?.Post(new SimpleNotification
|
||||
{
|
||||
Text = e.Message,
|
||||
Icon = FontAwesome.Solid.Times,
|
||||
});
|
||||
setBeatmapSet(beatmapSet, withHeartAnimation: false);
|
||||
};
|
||||
api.Queue(favouriteRequest);
|
||||
setLoading();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user