diff --git a/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate b/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate index 03b8044..e894edd 100644 Binary files a/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate and b/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/GHFollowers/Screens/FavoriteListVC.swift b/GHFollowers/Screens/FavoriteListVC.swift index df90633..1ffa69d 100644 --- a/GHFollowers/Screens/FavoriteListVC.swift +++ b/GHFollowers/Screens/FavoriteListVC.swift @@ -13,6 +13,10 @@ class FavoriteListVC: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBlue + + PersistanceManager.retrieveFavorites { (result) in + print(result) + } } } diff --git a/GHFollowers/Screens/FollowerListVC.swift b/GHFollowers/Screens/FollowerListVC.swift index db1edbb..6926557 100644 --- a/GHFollowers/Screens/FollowerListVC.swift +++ b/GHFollowers/Screens/FollowerListVC.swift @@ -69,11 +69,6 @@ class FollowerListVC: UIViewController { navigationItem.rightBarButtonItem = addButton } - @objc func addToFavorites() { - dismiss(animated: true) - } - - func configureCollectionView() { // init collection view @@ -117,8 +112,6 @@ class FollowerListVC: UIViewController { } - - func configureSearchController() { let searchController = UISearchController() @@ -137,6 +130,44 @@ class FollowerListVC: UIViewController { + // MARK: Add to Favorites Calls + @objc func addToFavorites() { + + // make network call with username to retreive the user avatar (shit code design) + // showloading + showLoadingView() + NetworkManager.shared.getUserInfo(for: username) { [weak self] result in + guard let self = self else { return } + self.dismissLoadingView() + + switch result { + + // success return the user + case .success(let user): + let favorite = Follower(login: user.login, avatarUrl: user.avatarUrl) + + PersistanceManager.updateWith(favorite: favorite, actionType: .add) { [weak self ] error in + guard let self = self else { return } + // check to see if we have recieved and error + guard let error = error else { + // if error was nil ( no error) + self.presentGFAlertOnMainThread(title: "Success!", message: "User was successfully added to the favorite list! 🥳", buttonTitle: "Horray!") + return + } + + self.presentGFAlertOnMainThread(title: "Somethig went wrong!", message: error.rawValue, buttonTitle: "Ok") + } + + case .failure(let error): + self.presentGFAlertOnMainThread(title: "Something went wrong", message: error.rawValue, buttonTitle: "Ok") + } + } + } + + + + + // MARK: API call func getFollowers(username: String, page: Int) { // api call for followers