-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor/#84] MyPageViewModel getButtonTitle, getButtonImage 메소드 삭제 …
…후 enum으로 처리
- Loading branch information
Showing
3 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...OS/Projects/Features/MyPageFeature/Sources/Refactor_MyFeature/MyPageButton_Refactor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// MyPageButton_Refactor.swift | ||
// MyPageFeatureInterface | ||
// | ||
// Created by 류희재 on 8/13/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
|
||
import SwiftUI | ||
|
||
import DSKit | ||
|
||
struct MyPageButton_Refactor: View { | ||
|
||
// @ObservedObject var viewModel: MyPageViewModel_Refactor | ||
|
||
var buttonType: MyPageButtonType | ||
|
||
var body: some View { | ||
ZStack { | ||
HStack() { | ||
if let image = buttonType.imageName { | ||
Image(image) | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
.frame(width: 24, height: 24) | ||
.padding(.trailing, 15) | ||
} | ||
Text(buttonType.titleText) | ||
.font(.text5_medium_16) | ||
Spacer() | ||
Image(uiImage: buttonType == .travel ? DSKitAsset.chevrongray.image : DSKitAsset.chevronRight.image) | ||
} | ||
.frame(maxWidth: .infinity) | ||
.frame(height: 58) | ||
.foregroundColor(buttonType == .travel ? DSKitAsset.gray5.swiftUIColor : DSKitAsset.whiteText.swiftUIColor) | ||
} | ||
.background(DSKitAsset.blackground.swiftUIColor) | ||
.onTapGesture { | ||
viewModel.myPageButtonClick(type: buttonType) | ||
} | ||
} | ||
} | ||
|
||
|
121 changes: 121 additions & 0 deletions
121
...Projects/Features/MyPageFeature/Sources/Refactor_MyFeature/MyPageViewModel_Refactor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// | ||
// MyPageViewModel.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 4/12/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import Core | ||
import DSKit | ||
|
||
public enum MyPageButtonType { | ||
case travel | ||
case market | ||
case term | ||
case info | ||
|
||
var titleText: String { | ||
switch self { | ||
case .travel: | ||
return StringLiteral.MyPageButton.travel | ||
case .market: | ||
return StringLiteral.MyPageButton.market | ||
case .term: | ||
return StringLiteral.MyPageButton.term | ||
case .info: | ||
return StringLiteral.MyPageButton.info | ||
} | ||
} | ||
|
||
var imageName: String? { | ||
switch self { | ||
case .travel: | ||
return "map" | ||
case .market: | ||
return "market" | ||
case .term, .info: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
|
||
class MyPageViewModel_Refactor: ObservableObject { | ||
@Published var isPresented = false | ||
@Published var alertType: CustomAlertType = .logout | ||
@Published var name = "" | ||
@Published var point = 0 | ||
@Published var navigateToPrepare = false | ||
|
||
//TODO: 네트워크 부분은 의존성 정리한 뒤에 다시 연결해봅시다 | ||
func getUserData() { | ||
// let provider = Providers.myPageProvider | ||
// provider.request(target: .getUserData, instance: BaseResponse<GetUserDataResponseDTO>.self) { data in | ||
// self.name = data.data?.name ?? "" | ||
// self.point = data.data?.point ?? 0 | ||
// } | ||
} | ||
|
||
func myPageButtonClick(type: MyPageButtonType) { | ||
switch type { | ||
case .term: | ||
guard let url = URL(string: StringLiteral.MyPageURL.term) else {return} | ||
UIApplication.shared.open(url) | ||
case .info: | ||
guard let url = URL(string: StringLiteral.MyPageURL.info) else {return} | ||
UIApplication.shared.open(url) | ||
case .market: | ||
navigateToPrepare = true | ||
default: | ||
return | ||
} | ||
} | ||
|
||
func backButtonClicked() { | ||
navigateToPrepare = false | ||
} | ||
|
||
func logoutButtonClicked() { | ||
isPresented = true | ||
alertType = .logout | ||
} | ||
|
||
func withdrawButtonClicked() { | ||
isPresented = true | ||
alertType = .withdraw | ||
} | ||
|
||
//TODO: 네트워크 부분은 의존성 정리한 뒤에 다시 연결해봅시다 | ||
func revokeUser() { | ||
// let provider = Providers.AuthProvider | ||
// provider.request(target: .revoke, instance: BaseResponse<EmptyResponseDTO>.self) { data in | ||
// UserManager.shared.revokeData() | ||
// } | ||
} | ||
|
||
//TODO: 네트워크 부분은 의존성 정리한 뒤에 다시 연결해봅시다 | ||
func logoutUser() { | ||
// let provider = Providers.AuthProvider | ||
// provider.request(target: .logout, instance: BaseResponse<EmptyResponseDTO>.self) { data in | ||
// UserManager.shared.clearLogout() | ||
// } | ||
} | ||
|
||
func confirmAction() { | ||
UserManager.shared.appStateString = "login" | ||
if alertType == .logout { | ||
logoutUser() | ||
isPresented = false | ||
} else { | ||
revokeUser() | ||
UserManager.shared.revokeData() | ||
isPresented = false | ||
} | ||
} | ||
|
||
func cancelAction() { | ||
isPresented = false | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
..._iOS/Projects/Features/MyPageFeature/Sources/Refactor_MyFeature/MyPageView_Refactor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// MyPageView.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 3/12/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import DSKit | ||
|
||
public struct MyPageView_Refactor: View { | ||
|
||
public init() {} | ||
|
||
@StateObject | ||
var viewModel = MyPageViewModel_Refactor() | ||
|
||
public var body: some View { | ||
VStack { | ||
Spacer() | ||
.frame(height: 64) | ||
ProfileView() | ||
Spacer() | ||
.frame(height: 36) | ||
MyInfoView() | ||
Spacer() | ||
.frame(height: 34) | ||
HMHInfoView() | ||
Spacer() | ||
AccountControlView() | ||
} | ||
.padding(20) | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.background(DSKitAsset.blackground.swiftUIColor) | ||
} | ||
} | ||
|
||
extension MyPageView_Refactor { | ||
private func ProfileView() -> some View { | ||
VStack { | ||
Image(uiImage: DSKitAsset.profile.image) | ||
.frame(width: 54, height: 54) | ||
.padding(10) | ||
//TODO: 서버통신이랑 이어지는 부분이라서 | ||
// Text(viewModel.getUserName()) | ||
// .font(.title4_semibold_20) | ||
Spacer() | ||
.frame(height: 16) | ||
HStack { | ||
Text(StringLiteral.MyPageAccountControl.point) | ||
.font(.text6_medium_14) | ||
//TODO: 서버통신이랑 이어지는 부분이라서 | ||
// Text(viewModel.getUserPoint()) | ||
// .font(.text6_medium_14) | ||
} | ||
.frame(maxWidth: .infinity) | ||
.frame(height: 40) | ||
.background(DSKitAsset.gray7.swiftUIColor) | ||
.cornerRadius(8) | ||
} | ||
.foregroundColor(DSKitAsset.whiteText.swiftUIColor) | ||
.frame(width: 133, height: 150) | ||
} | ||
private func MyInfoView() -> some View { | ||
VStack(spacing: 0) { | ||
MyPageButton_Refactor(viewModel: viewModel, buttonType: .travel) | ||
MyPageButton_Refactor(viewModel: viewModel, buttonType: .market) | ||
} | ||
.background(DSKitAsset.gray7.swiftUIColor) | ||
} | ||
private func HMHInfoView() -> some View { | ||
VStack(alignment: .leading, spacing: 0) { | ||
Text("정보") | ||
.font(.text4_semibold_16) | ||
.foregroundColor(DSKitAsset.gray2.swiftUIColor) | ||
.padding(.vertical, 14) | ||
MyPageButton_Refactor(viewModel: viewModel, buttonType: .info) | ||
MyPageButton_Refactor(viewModel: viewModel, buttonType: .term) | ||
} | ||
} | ||
private func AccountControlView() -> some View { | ||
HStack { | ||
Text(StringLiteral.MyPageAccountControl.logout) | ||
.font(.text6_medium_14) | ||
Rectangle() | ||
.frame(width: 1, height: 16) | ||
Text(StringLiteral.MyPageAccountControl.revoke) | ||
.font(.text6_medium_14) | ||
} | ||
.foregroundColor(DSKitAsset.gray3.swiftUIColor) | ||
.frame(height: 77) | ||
} | ||
} | ||
|