Skip to content

Commit

Permalink
Merge pull request #122 from wikimedia/searchMessages
Browse files Browse the repository at this point in the history
Search messages
  • Loading branch information
bgerstle committed Sep 18, 2015
2 parents c6d4289 + 171b51b commit a73324a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Wikipedia/Categories/NSString+Extras.h
Expand Up @@ -42,4 +42,6 @@

- (BOOL)wmf_isEqualToStringIgnoringCase:(NSString*)string;

- (NSString*)wmf_trim;

@end
4 changes: 4 additions & 0 deletions Wikipedia/Categories/NSString+Extras.m
Expand Up @@ -140,4 +140,8 @@ - (BOOL)wmf_isEqualToStringIgnoringCase:(NSString*)string {
return (NSOrderedSame == [self caseInsensitiveCompare:string]);
}

- (NSString*)wmf_trim {
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}

@end
13 changes: 11 additions & 2 deletions Wikipedia/UI-V5/WMFSearchViewController.m
Expand Up @@ -15,6 +15,7 @@


#import "NSString+FormattedAttributedString.h"
#import "UIViewController+Alert.h"

static NSUInteger const kWMFMinResultsBeforeAutoFullTextSearch = 12;

Expand Down Expand Up @@ -77,7 +78,7 @@ - (void)updateRecentSearchesVisibility {

- (void)updateRecentSearchesVisibility:(BOOL)animated {
BOOL hideRecentSearches =
[self.searchBar.text length] > 0 || [self.recentSearches countOfEntries] == 0;
[self.searchBar.text wmf_trim].length > 0 || [self.recentSearches countOfEntries] == 0;

[self setRecentSearchesHidden:hideRecentSearches animated:animated];
}
Expand Down Expand Up @@ -174,7 +175,7 @@ - (void)searchBarTextDidBeginEditing:(UISearchBar*)searchBar {
}

- (void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)searchText {
if ([searchText length] == 0) {
if ([searchText wmf_trim].length == 0) {
[self didCancelSearch];
return;
}
Expand Down Expand Up @@ -216,6 +217,9 @@ - (void)didCancelSearch {
}

- (void)searchForSearchTerm:(NSString*)searchTerm {
if ([searchTerm wmf_trim].length == 0) {
return;
}
@weakify(self);
[self.fetcher searchArticleTitlesForSearchTerm:searchTerm]
.thenOn(dispatch_get_main_queue(), ^id (WMFSearchResults* results){
Expand All @@ -241,9 +245,14 @@ - (void)searchForSearchTerm:(NSString*)searchTerm {
return [AnyPromise promiseWithValue:results];
}).then(^(WMFSearchResults* results){
if ([searchTerm isEqualToString:results.searchTerm]) {
if (results.articles.count == 0) {
[self showAlert:MWLocalizedString(@"search-no-matches", nil) type:ALERT_TYPE_TOP duration:2.0];
}
self.resultsListController.dataSource = results;
}
}).catch(^(NSError* error){
[self showAlert:error.userInfo[NSLocalizedDescriptionKey] type:ALERT_TYPE_TOP duration:2.0];

NSLog(@"%@", [error description]);
});
}
Expand Down

0 comments on commit a73324a

Please sign in to comment.