Skip to content

Commit 6249937

Browse files
authored
[NL-95] : 정보 삭제 추가 (#69)
* [NL-95] : 정보 삭제 기능 추가 * [NL-95] : HomeView, Mypage Error 처리 * [NL-95] : Home에서 result check 이후 다시 recommend 받을 수 있도록 수정 * [NL-95] : uuid 삭제시 기존 uuid 남아있는 문제 해결 * [NL-95] : Loading Indicator 추가
1 parent 19b8aca commit 6249937

File tree

17 files changed

+243
-27
lines changed

17 files changed

+243
-27
lines changed

App/Sources/AppDependencyHandler.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Home
1313
import Lib
1414
import Setting
1515
import UIKit
16+
import Onboarding
1617

1718
struct AppDependencyHandler: DependencyRegistrable {
1819
func register(to dependencyHandler: DependencyHandler) {
@@ -21,6 +22,12 @@ struct AppDependencyHandler: DependencyRegistrable {
2122
self.configureTabBarController()
2223
}
2324
}
25+
26+
dependencyHandler.register(key: DependencyKey.App.moveToSplashViewController) {
27+
Task { @MainActor in
28+
self.moveToSplashViewController()
29+
}
30+
}
2431
}
2532

2633
private func configureTabBarController() {
@@ -38,8 +45,18 @@ struct AppDependencyHandler: DependencyRegistrable {
3845
]
3946
UIApplication.shared.activeWindow?.rootViewController = tabBarController
4047
}
48+
49+
private func moveToSplashViewController() {
50+
let router = OnboardingRouter()
51+
let splashViewController = SplashViewcontroller(viewModel: SplashViewModel(), router: router)
52+
53+
let navigationController = UINavigationController(rootViewController: splashViewController)
54+
55+
UIApplication.shared.activeWindow?.rootViewController = navigationController
56+
}
4157
}
4258

59+
4360
extension UIApplication {
4461
fileprivate var activeWindow: UIWindow? {
4562
return

Common/Auth/Sources/DeviceUUIDManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class DeviceUUIDManager {
3333
return newUUID
3434
}
3535

36-
func deleteUUID() {
36+
func deleteUUID() throws {
3737
try? KeyChainService.remove(forKey: Constant.uuidKey)
3838
}
3939
}

Common/Auth/Sources/UserDataManager.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public final class UserDataManager {
6666
throw error
6767
}
6868
}
69+
70+
public func delete() async throws {
71+
do {
72+
try deviceUUIDManager.deleteUUID()
73+
user = nil
74+
} catch {
75+
throw error
76+
}
77+
}
6978

7079
public func getPublisher() -> AnyPublisher<Void, Never> {
7180
userPublisher

Common/Base/Sources/BaseViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ extension BaseViewController {
130130

131131
extension BaseViewController {
132132
public func showErrorPopup(action: @escaping () -> Void) {
133-
errorPopup.update(
134-
titile: "문제가 발생하였소", description: "잠시 후 다시 시도해 주시오.", actionButtonTitle: "확인")
133+
errorPopup.update(popUpModel: PopUpModel(title: "문제가 발생하였소", description: "잠시 후 다시 시도해 주시오.", actionButtonTitle: "확인", outButtonTitle: "취소"))
135134
errorPopup.update(style: .one)
136135
errorPopup.isHidden = false
137136

Common/Base/Sources/empty.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

Common/Lib/Sources/Router/DependencyKey.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public enum DependencyKey {
1111

1212
public enum App {
1313
public static let configureTabBarController = "configureTabBarController"
14+
public static let moveToSplashViewController = "moveToSplashViewController"
1415
}
1516
}

DesignSystem/DesignSystem/Sources/PopUp.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ import SnapKit
99
import Then
1010
import UIKit
1111

12+
public struct PopUpModel {
13+
let title: String
14+
let description: String?
15+
let actionButtonTitle: String
16+
let outButtonTitle: String
17+
18+
public init(title: String, description: String?, actionButtonTitle: String, outButtonTitle: String) {
19+
self.title = title
20+
self.description = description
21+
self.actionButtonTitle = actionButtonTitle
22+
self.outButtonTitle = outButtonTitle
23+
}
24+
25+
public init(title: String, actionButtonTitle: String, outButtonTitle: String) {
26+
self.title = title
27+
self.description = nil
28+
self.actionButtonTitle = actionButtonTitle
29+
self.outButtonTitle = outButtonTitle
30+
}
31+
}
32+
1233
public final class PopUp: UIView {
1334

1435
public enum Style: CaseIterable {
@@ -29,7 +50,7 @@ public final class PopUp: UIView {
2950
$0.alignment = .center
3051
}
3152

32-
private(set) lazy var deleteButton = UIButton().then {
53+
public private(set) lazy var deleteButton = UIButton().then {
3354
$0.setImage(STImages.xMark.image, for: .normal)
3455
}
3556

@@ -111,17 +132,14 @@ public final class PopUp: UIView {
111132
}
112133
}
113134

114-
public func update(
115-
titile: String, description: String? = nil, actionButtonTitle: String,
116-
outButtonTitle: String = "취소"
117-
) {
118-
titleLabel.styledText = titile
119-
descriptionLabel.styledText = description
135+
public func update(popUpModel: PopUpModel) {
136+
titleLabel.styledText = popUpModel.title
137+
descriptionLabel.styledText = popUpModel.description
120138
let style = Typography.Body_16_B
121139
style.color = STColors.white.color
122-
actionButton.setAttributedTitle(actionButtonTitle.set(style: style), for: .normal)
140+
actionButton.setAttributedTitle(popUpModel.actionButtonTitle.set(style: style), for: .normal)
123141
style.color = STColors.gray1.color
124-
outButton.setAttributedTitle(outButtonTitle.set(style: style), for: .normal)
142+
outButton.setAttributedTitle(popUpModel.outButtonTitle.set(style: style), for: .normal)
125143
}
126144

127145
public func update(style: Style) {
@@ -139,13 +157,12 @@ public final class PopUp: UIView {
139157
}
140158

141159
let popup = PopUp().then {
142-
$0.update(titile: "제목", description: "설명 텍스트입니다.", actionButtonTitle: "확인")
160+
$0.update(popUpModel : PopUpModel(title: "제목", description: "설명 텍스트입니다.", actionButtonTitle: "확인", outButtonTitle: "취소"))
143161
$0.update(style: .one)
144162
}
145163

146164
let popupTwo = PopUp().then {
147-
$0.update(
148-
titile: "제목", description: "설명 \n텍스트입니다.", actionButtonTitle: "확인", outButtonTitle: "취소")
165+
$0.update(popUpModel : PopUpModel(title: "제목", description: "설명 텍스트입니다.", actionButtonTitle: "확인", outButtonTitle: "취소"))
149166
$0.update(style: .two)
150167
}
151168

Feature/Home/Sources/Home/HomeViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ public final class HomeViewController: BaseViewController {
8787
self?.collectionView.reloadData()
8888
}
8989
.store(in: &cancellables)
90+
91+
viewModel.output.showError
92+
.receive(on: DispatchQueue.main)
93+
.sink { [weak self] retryAction in
94+
guard let self else { return }
95+
self.showErrorPopup(action: retryAction)
96+
}
97+
.store(in: &cancellables)
9098
}
9199

92100
private func createLayout() -> UICollectionViewCompositionalLayout {

Feature/Home/Sources/Home/HomeViewModel.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class HomeViewModel {
2222
struct Output {
2323
let isLoading = CurrentValueSubject<Bool, Never>(false)
2424
let sections = CurrentValueSubject<[any HomeCellModel], Never>([])
25+
let showError = PassthroughSubject<()->Void, Never>()
2526
}
2627

2728
@Injected var homeService: HomeService
@@ -76,6 +77,8 @@ public final class HomeViewModel {
7677
to: HomeRoute.lottoResult, how: .push(hidesBottomBarWhenPushed: true),
7778
with: ["round": homeService.round as Any])
7879
}
80+
81+
fetchResult()
7982
}
8083
}
8184
}
@@ -89,8 +92,11 @@ extension HomeViewModel {
8992
let sections = try await homeService.fetch()
9093
output.sections.send(sections)
9194
} catch {
92-
// TODO: 에러 처리
93-
print(error)
95+
output.isLoading.send(false)
96+
output.showError.send {[weak self] in
97+
guard let self else { return }
98+
self.fetch()
99+
}
94100
}
95101
output.isLoading.send(false)
96102
}
@@ -103,10 +109,28 @@ extension HomeViewModel {
103109
let sections = try await homeService.fetchLottoRecommendation()
104110
output.sections.send(sections)
105111
} catch {
106-
// TODO: 에러 처리
107-
print(error)
112+
output.isLoading.send(false)
113+
output.showError.send {[weak self] in
114+
guard let self else { return }
115+
self.fetchRecommendation()
116+
}
108117
}
109118
output.isLoading.send(false)
110119
}
111120
}
121+
122+
fileprivate func fetchResult() {
123+
let name = userDataManager.user?.name ?? ""
124+
var sections : [any HomeCellModel] = []
125+
126+
output.sections.value.forEach { section in
127+
if let _ = section as? HomeRecommendationCollectionViewCellModel {
128+
sections.append(HomeRecommendationCollectionViewCellModel(title: "\(name)님을 위한 로또 번호 추천", state: .needsRecommendation))
129+
} else {
130+
sections.append(section)
131+
}
132+
}
133+
134+
output.sections.send(sections)
135+
}
112136
}

Feature/Home/Sources/LottoResult/LottoResultViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ final class LottoResultViewController: BaseViewController {
152152
}
153153
}
154154
.store(in: &cancellables)
155+
156+
viewModel.output.showError
157+
.receive(on: DispatchQueue.main)
158+
.sink { [weak self] retryAction in
159+
guard let self else { return }
160+
self.showErrorPopup(action: retryAction)
161+
}
162+
.store(in: &cancellables)
155163

156164
viewModel.output.back
157165
.receive(on: DispatchQueue.main)

0 commit comments

Comments
 (0)