Skip to content

Commit

Permalink
Merge branch 'improveLoginVCToFeedVCDevelop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SHcommit committed Nov 2, 2022
2 parents c08f133 + 80f65ca commit b616457
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
Expand Up @@ -38,5 +38,13 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "closure #1 in MainHomeTabController.authenticationCompletion():MainHomeTabController.swift">
<PersistentStrings>
<PersistentString
value = "userInfo">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>
11 changes: 7 additions & 4 deletions Clone App/Instagram/Instagram/Controller/FeedController.swift
Expand Up @@ -10,14 +10,17 @@ import Firebase

class FeedController: UICollectionViewController {

private let reuseIdentifier = "FeedCell"

//MARK: - LifeCycle
override func viewDidLoad() {
super.viewDidLoad()
collectionView.register(FeedCell.self, forCellWithReuseIdentifier: reuseIdentifier )
collectionView.register(FeedCell.self, forCellWithReuseIdentifier: FEEDCELLRESUIDENTIFIER )
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
collectionView.register(FeedCell.self, forCellWithReuseIdentifier: FEEDCELLRESUIDENTIFIER)
setupNavigationUI()

}
}

Expand Down Expand Up @@ -50,7 +53,7 @@ extension FeedController {
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as? FeedCell else {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FEEDCELLRESUIDENTIFIER, for: indexPath) as? FeedCell else {
fatalError()
}

Expand Down
Expand Up @@ -17,10 +17,26 @@ class MainHomeTabController: UITabBarController {
}
}

private var isLogin: Bool? {
didSet {
guard let isLogin = isLogin else { return }
if !isLogin {
DispatchQueue.main.async {
self.presentLoginScene()
}
}
}
}


//MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
configure()

}
Expand All @@ -29,15 +45,14 @@ class MainHomeTabController: UITabBarController {
configure()
}

}
}

//MARK: - Helpers
extension MainHomeTabController {

func configure() {
customTabBarUI()
fetchUserInfo()
checkIfUserIsLoggedIn()
isLogin = isUserLogined()
}

func configureViewControllers() {
Expand All @@ -53,7 +68,7 @@ extension MainHomeTabController {

let notifications = templateNavigationController(unselectedImage: .imageLiteral(name: "like_unselected"), selectedImage: .imageLiteral(name: "like_selected"), rootVC: NotificationController())

var profileVC = ProfileController(user: userVM.getUserInfoModel())
let profileVC = ProfileController(user: userVM.getUserInfoModel())
UserService.fetchUserProfile(userProfile: userVM.getUserProfileURL()) { image in
profileVC.profileImage = image
}
Expand Down Expand Up @@ -122,13 +137,16 @@ extension MainHomeTabController {


//MARK: - API. check user's membership
func checkIfUserIsLoggedIn() {
if CURRENT_USER == nil {
self.view.isHidden = true
self.presentLoginScene()
func isUserLogined() -> Bool {
if Auth.auth().currentUser == nil {
return false
}
fetchUserInfo()
return true
}



func presentLoginScene() {
let controller = LoginController()
controller.authDelegate = self
Expand All @@ -143,9 +161,12 @@ extension MainHomeTabController {
//MARK: - Implement AuthentificationDelegate
extension MainHomeTabController: AuthentificationDelegate {
func authenticationCompletion() {
fetchUserInfo()
UserService.fetchCurrentUserInfo() { userInfo in
guard let userInfo = userInfo else { return }
self.viewDidLoad()
self.userVM = UserInfoViewModel(user: userInfo, profileImage: nil)
}
self.dismiss(animated: false)
}


}
5 changes: 5 additions & 0 deletions Clone App/Instagram/Instagram/Utils/Constants.swift
Expand Up @@ -20,3 +20,8 @@ let AUTH = Auth.auth()
//MARK: - profile subview's ID
let COLLECTIONHEADERREUSEABLEID = "UserProfileCollectionHeaderView"
let CELLREUSEABLEID = "CollectionViewCell"


//MARK: - FeedVieController subview's ID

let FEEDCELLRESUIDENTIFIER = "FeedCell"

0 comments on commit b616457

Please sign in to comment.