mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:23:22 +08:00
Add proper offline & loading state handling to user profile overlay
This commit is contained in:
parent
c759b743dc
commit
a124c967df
@ -51,6 +51,31 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
AddStep("show user", () => profile.ShowUser(new APIUser { Id = 1 }));
|
||||
AddToggleStep("toggle visibility", visible => profile.State.Value = visible ? Visibility.Visible : Visibility.Hidden);
|
||||
AddStep("log out", () => dummyAPI.Logout());
|
||||
AddStep("log back in", () => dummyAPI.Login("username", "password"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoading()
|
||||
{
|
||||
GetUserRequest pendingRequest = null!;
|
||||
|
||||
AddStep("set up request handling", () =>
|
||||
{
|
||||
dummyAPI.HandleRequest = req =>
|
||||
{
|
||||
if (req is GetUserRequest getUserRequest)
|
||||
{
|
||||
pendingRequest = getUserRequest;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
});
|
||||
AddStep("show user", () => profile.ShowUser(new APIUser { Id = 1 }));
|
||||
AddWaitStep("wait some", 3);
|
||||
AddStep("complete request", () => pendingRequest.TriggerSuccess(TEST_USER));
|
||||
}
|
||||
|
||||
public static readonly APIUser TEST_USER = new APIUser
|
||||
|
@ -13,6 +13,8 @@ using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays.Profile;
|
||||
@ -26,6 +28,11 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
public partial class UserProfileOverlay : FullscreenOverlay<ProfileHeader>
|
||||
{
|
||||
protected override Container<Drawable> Content => onlineViewContainer;
|
||||
|
||||
private readonly OnlineViewContainer onlineViewContainer;
|
||||
private readonly LoadingLayer loadingLayer;
|
||||
|
||||
private ProfileSection? lastSection;
|
||||
private ProfileSection[]? sections;
|
||||
private GetUserRequest? userReq;
|
||||
@ -40,6 +47,14 @@ namespace osu.Game.Overlays
|
||||
public UserProfileOverlay()
|
||||
: base(OverlayColourScheme.Pink)
|
||||
{
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
onlineViewContainer = new OnlineViewContainer($"Sign in to view the {Header.Title.Title}")
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
loadingLayer = new LoadingLayer(true)
|
||||
});
|
||||
}
|
||||
|
||||
protected override ProfileHeader CreateHeader() => new ProfileHeader();
|
||||
@ -125,6 +140,7 @@ namespace osu.Game.Overlays
|
||||
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID, ruleset) : new GetUserRequest(user.Username, ruleset);
|
||||
userReq.Success += u => userLoadComplete(u, ruleset);
|
||||
API.Queue(userReq);
|
||||
loadingLayer.Show();
|
||||
}
|
||||
|
||||
private void userLoadComplete(APIUser user, IRulesetInfo? ruleset)
|
||||
@ -151,6 +167,8 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadingLayer.Hide();
|
||||
}
|
||||
|
||||
private partial class ProfileSectionTabControl : OverlayTabControl<ProfileSection>
|
||||
|
Loading…
Reference in New Issue
Block a user