From 2d6630dda9f7c3df0da956c4644f94342d2bb747 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 31 Oct 2018 00:13:21 +0300 Subject: Refresh data on path changes --- Juick/ViewControllers/DiscoverViewController.m | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'Juick/ViewControllers/DiscoverViewController.m') diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index b09e1df..092c19c 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -23,7 +23,6 @@ @implementation DiscoverViewController -(void) viewDidLoad { - [super viewDidLoad]; self.messagesDelegate = self; if ([User isAuthenticated]) { [User checkIsValid:^(BOOL success) { @@ -33,7 +32,8 @@ [self.tabBarItem setTitle:@"My feed"]; self.navigationController.visibleViewController.navigationItem.title = @"My feed"; } - [self refreshData:NO]; + [self setShouldScrollToBottomOnRefresh:NO]; + [self refreshData]; } else { [User throwUnableToLogin:self]; } @@ -45,8 +45,10 @@ [self.tabBarItem setTitle:@"Discover"]; self.navigationController.visibleViewController.navigationItem.title = @"Discover"; } - [self refreshData:NO]; + [self setShouldScrollToBottomOnRefresh:NO]; + [self refreshData]; } + [super viewDidLoad]; self.appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate; } @@ -83,17 +85,19 @@ Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; mid = msg.mid; } - ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; - [threadVC setPath:[APIClient threadUrl]]; - [threadVC setParams:@{@"mid": mid }]; - [threadVC refreshData:scrollToEnd]; + if ([mid integerValue] > 0) { + ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; + [threadVC setPath:[APIClient threadUrl]]; + [threadVC setParams:@{@"mid": mid }]; + [threadVC setShouldScrollToBottomOnRefresh:scrollToEnd]; + } } if ([segue.identifier isEqual: @"profileSegue"]) { BlogViewController *blogVC = (BlogViewController *)segue.destinationViewController; [blogVC setUname:self.selectedUser]; [blogVC setTitle:self.selectedUser]; blogVC.path = [NSString stringWithFormat:@"/messages?uname=%@", self.selectedUser]; - [blogVC refreshData:NO]; + [blogVC setShouldScrollToBottomOnRefresh:NO]; } } - (IBAction)filterAction:(id)sender { @@ -110,7 +114,7 @@ self.params = nil; [self.messages removeAllObjects]; [self.tableView reloadData]; - [self refreshData:NO]; + [self setShouldScrollToBottomOnRefresh:NO]; }]]; [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discover" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { self.path = [APIClient messagesUrl]; @@ -119,7 +123,7 @@ self.params = nil; [self.messages removeAllObjects]; [self.tableView reloadData]; - [self refreshData:NO]; + [self setShouldScrollToBottomOnRefresh:NO]; }]]; [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discussions" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { self.path = [APIClient discussionsUrl]; @@ -128,7 +132,7 @@ self.params = nil; [self.messages removeAllObjects]; [self.tableView reloadData]; - [self refreshData:NO]; + [self setShouldScrollToBottomOnRefresh:NO]; }]]; [filterAlert.view setTintColor:[ColorScheme linkColor]]; UIPopoverPresentationController *popover = [filterAlert popoverPresentationController]; @@ -150,7 +154,7 @@ NSNumber *lastMid = lastMsg.mid; self.params = [@{@"before_mid":lastMid} mutableCopy]; } - [self refreshData:NO]; + [self setShouldScrollToBottomOnRefresh:NO]; } } -- cgit v1.2.3