Skip to content

Commit

Permalink
Re-fetch site info after Jetpack login
Browse files Browse the repository at this point in the history
  • Loading branch information
crazytonyli committed Oct 2, 2024
1 parent 46ddb2c commit c3e32dd
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions WordPress/Classes/ViewRelated/Stats/StatsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,24 @@ - (void)initStats
return;
}

[self refreshStatus];
__weak __typeof(self) weakSelf = self;
[self refreshStatusWithCompletion:^{
[weakSelf promptForJetpackCredentials];
}];
}

- (void)refreshStatus
- (void)refreshStatusWithCompletion:(void (^)(void))completion
{
[self.loadingIndicator startAnimating];
BlogService *blogService = [[BlogService alloc] initWithCoreDataStack:[ContextManager sharedInstance]];
__weak __typeof(self) weakSelf = self;
[blogService syncBlog:self.blog success:^{
[self.loadingIndicator stopAnimating];
[weakSelf promptForJetpackCredentials];
[weakSelf.loadingIndicator stopAnimating];
completion();
} failure:^(NSError * _Nonnull error) {
DDLogError(@"Error refreshing blog status when loading stats: %@", error);
[self.loadingIndicator stopAnimating];
[weakSelf promptForJetpackCredentials];
[weakSelf.loadingIndicator stopAnimating];
completion();
}];
}

Expand All @@ -137,11 +140,14 @@ - (void)promptForJetpackCredentials
self.showingJetpackLogin = YES;
JetpackLoginViewController *controller = [[JetpackLoginViewController alloc] initWithBlog:self.blog];
__weak JetpackLoginViewController *safeController = controller;
__weak __typeof(self) weakSelf = self;
[controller setCompletionBlock:^(){
[safeController.view removeFromSuperview];
[safeController removeFromParentViewController];
self.showingJetpackLogin = NO;
[self initStats];
[safeController.view removeFromSuperview];
[safeController removeFromParentViewController];
weakSelf.showingJetpackLogin = NO;
[weakSelf refreshStatusWithCompletion:^{
[weakSelf initStats];
}];
}];

[self addChildViewController:controller];
Expand Down

0 comments on commit c3e32dd

Please sign in to comment.