Skip to content

Commit ca51ce6

Browse files
committed
[#234] 탭바에서 마이페이지 연결되는 로직 설계 완료
- 액세스토큰 유무를 판별해서 접근할 수 있는 로직 연결
1 parent 6f12562 commit ca51ce6

File tree

3 files changed

+72
-60
lines changed

3 files changed

+72
-60
lines changed

EATSSU/App/Sources/Presentation/Home/ViewController/HomeViewController.swift

-46
Original file line numberDiff line numberDiff line change
@@ -75,55 +75,9 @@ final class HomeViewController: BaseViewController {
7575
private func setupNavigationBar() {
7676
let logoImageView = UIImageView(image: EATSSUDesignAsset.Images.mainLogoSmall.image)
7777
navigationItem.titleView = logoImageView
78-
79-
let rightButton = UIBarButtonItem(
80-
image: EATSSUDesignAsset.Images.myPageIcon.image,
81-
style: .plain,
82-
target: self,
83-
action: #selector(didTapRightBarButton)
84-
)
85-
rightButton.tintColor = EATSSUDesignAsset.Color.Main.primary.color
86-
navigationItem.rightBarButtonItem = rightButton
8778
navigationController?.isNavigationBarHidden = false
8879
}
8980

90-
@objc
91-
private func didTapRightBarButton() {
92-
if RealmService.shared.isAccessTokenPresent() {
93-
navigateToMyPage()
94-
} else {
95-
presentLoginAlert()
96-
}
97-
}
98-
99-
private func navigateToMyPage() {
100-
let myPageVC = MyPageViewController()
101-
navigationController?.pushViewController(myPageVC, animated: true)
102-
}
103-
104-
private func presentLoginAlert() {
105-
let alert = UIAlertController(title: "로그인이 필요한 서비스입니다",
106-
message: "로그인 하시겠습니까?",
107-
preferredStyle: .alert)
108-
let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self] _ in
109-
self?.navigateToLogin()
110-
}
111-
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)
112-
alert.addAction(confirmAction)
113-
alert.addAction(cancelAction)
114-
present(alert, animated: true, completion: nil)
115-
}
116-
117-
private func navigateToLogin() {
118-
let loginVC = LoginViewController()
119-
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
120-
let sceneDelegate = windowScene.delegate as? SceneDelegate,
121-
let window = sceneDelegate.window
122-
{
123-
window.replaceRootViewController(loginVC)
124-
}
125-
}
126-
12781
// MARK: - Firebase
12882

12983
private func logFirebaseEvent() {

EATSSU/App/Sources/Presentation/MyPage/ViewController/MyPageViewController.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ final class MyPageViewController: BaseViewController {
2323
private var nickName = ""
2424
private var switchState = false
2525
private let myPageTableLabelList = MyPageLocalData.myPageTableLabelList
26+
private let hasAccessToken: Bool
27+
28+
// TODO: 리뷰에서 엑세스 토큰을 확인하는 코드 정상처리 되는지 확인
29+
init(hasAccessToken: Bool) {
30+
self.hasAccessToken = hasAccessToken
31+
super.init(nibName: nil, bundle: nil)
32+
}
2633

2734
// MARK: - UI Components
2835

@@ -40,7 +47,11 @@ final class MyPageViewController: BaseViewController {
4047
override func viewWillAppear(_ animated: Bool) {
4148
super.viewWillAppear(animated)
4249

43-
nickName = UserInfoManager.shared.getCurrentUserInfo()?.nickname ?? "실패"
50+
if hasAccessToken {
51+
nickName = UserInfoManager.shared.getCurrentUserInfo()?.nickname ?? "다시 시도하세요"
52+
} else {
53+
nickName = "로그인을 해주세요"
54+
}
4455
mypageView.setUserInfo(nickname: nickName)
4556
}
4657

@@ -72,8 +83,7 @@ final class MyPageViewController: BaseViewController {
7283
private func setFirebaseTask() {
7384
FirebaseRemoteConfig.shared.fetchRestaurantInfo()
7485

75-
#if DEBUG
76-
#else
86+
#if !DEBUG
7787
Analytics.logEvent("MypageViewControllerLoad", parameters: nil)
7888
#endif
7989
}

EATSSU/App/Sources/Presentation/TabBar/RootTabBarViewController.swift

+59-11
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,81 @@
77

88
import UIKit
99

10+
import EATSSUDesign
11+
1012
class RootTabBarViewController: UITabBarController {
1113
override func viewDidLoad() {
1214
super.viewDidLoad()
1315

16+
delegate = self
17+
1418
setupTabBar()
1519
}
1620

1721
private func setupTabBar() {
1822
let homeViewController = HomeViewController()
1923
let searchViewController = MapsViewController()
20-
let settingsViewController = MyPageViewController()
24+
let mypageViewController = MyPageViewController(hasAccessToken: RealmService.shared.isAccessTokenPresent())
2125

22-
// 각 뷰컨트롤러를 네비게이션 컨트롤러로 래핑
2326
let homeNav = UINavigationController(rootViewController: homeViewController)
24-
let searchNav = UINavigationController(rootViewController: searchViewController)
25-
let settingsNav = UINavigationController(rootViewController: settingsViewController)
27+
let mapNav = UINavigationController(rootViewController: searchViewController)
28+
let mypageNav = UINavigationController(rootViewController: mypageViewController)
2629

27-
// 탭바 아이템 설정
2830
homeNav.tabBarItem = UITabBarItem(title: "Home", image: UIImage(systemName: "house.fill"), tag: 0)
29-
searchNav.tabBarItem = UITabBarItem(title: "Search", image: UIImage(systemName: "map.fill"), tag: 1)
30-
settingsNav.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gearshape.fill"), tag: 2)
31+
mapNav.tabBarItem = UITabBarItem(title: "Search", image: UIImage(systemName: "map.fill"), tag: 1)
32+
mypageNav.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(systemName: "gearshape.fill"), tag: 2)
3133

32-
// 탭바 컨트롤러에 뷰컨트롤러 추가
33-
viewControllers = [homeNav, searchNav, settingsNav]
34+
viewControllers = [homeNav, mapNav, mypageNav]
3435

35-
// 탭바 스타일 설정 (선택적)
36-
tabBar.tintColor = .systemBlue
36+
tabBar.tintColor = EATSSUDesignAsset.Color.Main.primary.color
3737
tabBar.backgroundColor = .white
3838
}
39+
40+
// FIXME: EATSSUKit으로 이관하여 재사용성 높이기
41+
private func presentLoginAlert() {
42+
let alert = UIAlertController(title: "로그인이 필요한 서비스입니다",
43+
message: "로그인 하시겠습니까?",
44+
preferredStyle: .alert)
45+
let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self] _ in
46+
self?.navigateToLogin()
47+
}
48+
alert.addAction(confirmAction)
49+
present(alert, animated: true, completion: nil)
50+
}
51+
52+
// FIXME: EATSSUKit으로 이관하여 재사용성 높이기
53+
private func navigateToLogin() {
54+
let loginVC = LoginViewController()
55+
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
56+
let sceneDelegate = windowScene.delegate as? SceneDelegate,
57+
let window = sceneDelegate.window
58+
{
59+
window.replaceRootViewController(loginVC)
60+
}
61+
}
62+
}
63+
64+
// MARK: - UITabBarControllerDelegate
65+
66+
extension RootTabBarViewController: UITabBarControllerDelegate {
67+
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
68+
guard let selectedIndex = tabBarController.viewControllers?.firstIndex(of: viewController) else { return }
69+
70+
if selectedIndex == 2 {
71+
#if DEBUG
72+
print("마이페지이 탭(tag 2)이 선택되었습니다.")
73+
#endif
74+
handleSettingsTabSelected()
75+
}
76+
}
77+
78+
private func handleSettingsTabSelected() {
79+
if !RealmService.shared.isAccessTokenPresent() {
80+
presentLoginAlert()
81+
} else {
82+
#if DEBUG
83+
print("MyPageViewController로 이동")
84+
#endif
85+
}
86+
}
3987
}

0 commit comments

Comments
 (0)