2828#import " CSMenuUserFeedDataSource.h"
2929#import " CSMenuSearchFeedDataSource.h"
3030
31+ #import " CSFeedSearcher.h"
32+
3133@interface CSMenuLeftViewController ()
3234{
3335 CSMenuUserFeedDataSource *userFeedDataSource;
3436 CSMenuSearchFeedDataSource *searchFeedDataSource;
37+ CSFeedSearcher *feedSearcher;
3538}
3639
3740@end
@@ -46,9 +49,11 @@ - (void)viewDidLoad
4649 [super viewDidLoad ];
4750 self.currentUser = [User current ];
4851 self.feeds = [[NSMutableSet alloc ] init ];
49- self.usersFeeds = [[NSMutableSet alloc ] init ];
5052 [self setUpDataSources ];
5153
54+ // Setup feedSearch API
55+ feedSearcher = [[CSFeedSearcher alloc ] init ];
56+
5257 // Set tableViewStyle
5358 CSEnhancedTableViewStyle *tableViewStyle = [[CSEnhancedTableViewStyleDark alloc ] init ];
5459 self.tableView_feeds .tableViewStyle = tableViewStyle;
@@ -70,13 +75,15 @@ - (void)viewDidLoad
7075 [removedFeeds removeObjectsInArray: [new allObjects ]];
7176
7277 for ( Feed *feed in removedFeeds ){
73- [[self usersFeeds ] removeObject: feed];
78+ [[self feeds ] removeObject: feed];
7479 }
7580
7681 for ( Feed *feed in addedFeeds ){
77- [[self usersFeeds ] addObject: feed];
82+ [[self feeds ] addObject: feed];
7883 }
79- self.feeds = self.usersFeeds ;
84+ self.tableView_feeds .dataSource = userFeedDataSource;
85+ [userFeedDataSource updateWithFeeds: self .feeds];
86+
8087 [self .tableView_feeds reloadData ];
8188 }
8289 insertionBlock: nil
@@ -93,8 +100,6 @@ - (void)viewDidLoad
93100
94101 [userFeedDataSource updateWithFeeds: self .feeds];
95102 self.tableView_feeds .dataSource = userFeedDataSource;
96-
97- self.searchingFeeds = NO ;
98103}
99104
100105- (void )setUpDataSources
@@ -124,34 +129,39 @@ - (void)menuStateEventOccurred:(NSNotification *)notification {
124129 weakSelf.textField_searchInput .text = @" " ;
125130 [weakSelf.tableView_feeds setEditing: NO animated: YES ];
126131 weakSelf.menuContainerViewController .panMode = MFSideMenuPanModeDefault;
132+ weakSelf.tableView_feeds .dataSource = userFeedDataSource;
133+ [weakSelf.tableView_feeds reloadData ];
127134 break ;
128135 }
129136}
130137
131138- (void )searchFieldDidChange
132139{
133140 if (self.textField_searchInput .text && self.textField_searchInput .text .length > 0 ){
134- [searchFeedDataSource updateWithFeeds: self .feeds];
141+ NSMutableSet *searchedFeeds = [[NSMutableSet alloc ] init ];
142+ [searchFeedDataSource updateWithFeeds: searchedFeeds];
135143 self.tableView_feeds .dataSource = searchFeedDataSource;
136- [self .tableView_feeds reloadData ];
137144
138- NSMutableSet *searchedFeeds = [[NSMutableSet alloc ] init ];
139145 if ([self .textField_searchInput.text hasPrefix: @" http" ]){
140- NSLog (@" ADDING A URL" );
146+ // Get the local context
147+ NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread ];
148+
149+ // Create a new Feed in the current thread context
150+ Feed *customFeed = [Feed MR_createInContext: localContext];
151+ customFeed.name = self.textField_searchInput .text ;
152+ customFeed.url = self.textField_searchInput .text ;
153+
154+ [searchedFeeds addObject: customFeed];
141155 }
142156 else {
143- NSLog ( @" SEARCHING " ) ;
157+ [feedSearcher feedsLike: self .textField_searchInput.text] ;
144158 }
145-
146- self.feeds = searchedFeeds;
159+
147160 [self .tableView_feeds reloadData ];
148161 }
149162 else {
150163 self.tableView_feeds .dataSource = userFeedDataSource;
151164 [self .tableView_feeds reloadData ];
152-
153- self.feeds = self.usersFeeds ;
154- [self .tableView_feeds reloadData ];
155165 }
156166}
157167
@@ -178,8 +188,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
178188 } else {
179189 [tableView deselectRowAtIndexPath: indexPath animated: YES ];
180190 }
181-
182- // [self.menuContainerViewController setMenuState:MFSideMenuStateClosed completion:^{}];
183191}
184192
185193@end
0 commit comments