Inline request flow to make it easier to understand

This commit is contained in:
Dean Herbert 2021-05-26 14:37:52 +09:00
parent 0f21510b8b
commit d165a75823

View File

@ -21,7 +21,7 @@ namespace osu.Game.Overlays
private readonly NewsSidebar sidebar; private readonly NewsSidebar sidebar;
private readonly Container content; private readonly Container content;
private GetNewsRequest lastRequest; private GetNewsRequest request;
private Cursor lastCursor; private Cursor lastCursor;
@ -139,66 +139,64 @@ namespace osu.Game.Overlays
private void loadListing(int? year = null) private void loadListing(int? year = null)
{ {
beginLoading();
Header.SetFrontPage(); Header.SetFrontPage();
displayedYear = year; displayedYear = year;
lastCursor = null; lastCursor = null;
performListingRequest(response => beginLoading(true);
request = new GetNewsRequest(displayedYear);
request.Success += response => Schedule(() =>
{ {
lastCursor = response.Cursor;
sidebar.Metadata.Value = response.SidebarMetadata; sidebar.Metadata.Value = response.SidebarMetadata;
var listing = new ArticleListing(response); LoadDisplay(new ArticleListing(response)
listing.RequestMorePosts += getMorePosts; {
RequestMorePosts = getMorePosts
LoadDisplay(listing); });
}); });
}
private void loadArticle(string article) API.PerformAsync(request);
{
beginLoading();
Header.SetArticle(article);
// Temporary, should be handled by ArticleDisplay later
LoadDisplay(Empty());
} }
private void getMorePosts() private void getMorePosts()
{ {
lastRequest?.Cancel(); beginLoading(false);
performListingRequest(response =>
request = new GetNewsRequest(displayedYear, lastCursor);
request.Success += response => Schedule(() =>
{ {
lastCursor = response.Cursor;
if (content.Child is ArticleListing listing) if (content.Child is ArticleListing listing)
listing.AddPosts(response); listing.AddPosts(response);
}); });
API.PerformAsync(request);
} }
private void performListingRequest(Action<GetNewsResponse> onSuccess) private void loadArticle(string article)
{ {
lastRequest = new GetNewsRequest(displayedYear, lastCursor); // This is not yet implemented nor called from anywhere.
lastRequest.Success += response => Schedule(() => beginLoading(true);
{
lastCursor = response.Cursor;
onSuccess?.Invoke(response);
});
API.PerformAsync(lastRequest); Header.SetArticle(article);
LoadDisplay(Empty());
} }
private void beginLoading() private void beginLoading(bool showLoadingOverlay)
{ {
lastRequest?.Cancel(); request?.Cancel();
cancellationToken?.Cancel(); cancellationToken?.Cancel();
Loading.Show();
if (showLoadingOverlay)
Loading.Show();
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
lastRequest?.Cancel(); request?.Cancel();
cancellationToken?.Cancel(); cancellationToken?.Cancel();
base.Dispose(isDisposing); base.Dispose(isDisposing);
} }