Skip to content

Commit

Permalink
[Refactor/#122] MyView 리펙토링
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Nov 25, 2024
1 parent 73dfa9a commit ea0ddfc
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 217 deletions.
152 changes: 70 additions & 82 deletions HMH_Tuist_iOS/Projects/App/Derived/InfoPlists/HMH-iOS-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,75 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.HMH.dailyTask</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kakao$(KAKAO_API_KEY)</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>KAKAO_API_KEY</key>
<string>$(KAKAO_API_KEY)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaokompassauth</string>
<string>kakaolink</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIAppFonts</key>
<array>
<string>Pretendard-Regular.otf</string>
<string>Pretendard-SemiBold.otf</string>
<string>Pretendard-Medium.otf</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.HMH.dailyTask</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kakao$(KAKAO_API_KEY)</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>KAKAO_API_KEY</key>
<string>$(KAKAO_API_KEY)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaokompassauth</string>
<string>kakaolink</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIAppFonts</key>
<array>
<string>Pretendard-Regular.otf</string>
<string>Pretendard-SemiBold.otf</string>
<string>Pretendard-Medium.otf</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict/>
</dict>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,121 +1,66 @@
//
// MyPageViewModel.swift
// HMH_iOS
// MyPageFeature
//
// Created by Seonwoo Kim on 4/12/24.
// Created by 류희재 on 11/26/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import SwiftUI
import Combine

import Core
import DSKit

public enum MyPageButtonType {
case travel
case market
case term
case info
}


class MyPageViewModel: ObservableObject {
@Published var isPresented = false
@Published var alertType: CustomAlertType = .logout
@Published var name = ""
@Published var point = 0
@Published var navigateToPrepare = false

func getButtonTitle(type: MyPageButtonType) -> String {
switch type {
case .travel:
return StringLiteral.MyPageButton.travel
case .market:
return StringLiteral.MyPageButton.market
case .term:
return StringLiteral.MyPageButton.term
case .info:
return StringLiteral.MyPageButton.info
}
}

func getButtonImage(type: MyPageButtonType) -> String? {
switch type {
case .travel:
return "map"
case .market:
return "market"
case .term, .info:
return nil
}
}

//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
// }
}
private var useCase: MyPageUseCaseType
private var cancelBag = CancelBag()

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
}
init(useCase: MyPageUseCaseType) {
self.useCase = useCase
}

func backButtonClicked() {
navigateToPrepare = false
}
@Published private(set) var state = State(
alertType: .logout,
name: "",
point: 0
)

func logoutButtonClicked() {
isPresented = true
alertType = .logout
}
//MARK: Action

func withdrawButtonClicked() {
isPresented = true
alertType = .withdraw
enum Action {
case onAppearEvent
case logoutButtonDidTap
case withdrawButtonDidTap
case confirmButtonDidTap
}

//TODO: 네트워크 부분은 의존성 정리한 뒤에 다시 연결해봅시다
func revokeUser() {
// let provider = Providers.AuthProvider
// provider.request(target: .revoke, instance: BaseResponse<EmptyResponseDTO>.self) { data in
// UserManager.shared.revokeData()
// }
}
//MARK: State

//TODO: 네트워크 부분은 의존성 정리한 뒤에 다시 연결해봅시다
func logoutUser() {
// let provider = Providers.AuthProvider
// provider.request(target: .logout, instance: BaseResponse<EmptyResponseDTO>.self) { data in
// UserManager.shared.clearLogout()
// }
struct State {
var alertType: CustomAlertType
var name: String
var point: Int
}

func confirmAction() {
UserManager.shared.appStateString = "login"
if alertType == .logout {
logoutUser()
isPresented = false
} else {
revokeUser()
UserManager.shared.revokeData()
isPresented = false
func send(action: Action) {
switch action {
case .onAppearEvent:
useCase.getUserDate()
.sink { _ in
} receiveValue: { [weak self] data in
self?.state.name = data.name
self?.state.point = data.point
}.store(in: cancelBag)

case .logoutButtonDidTap:
state.alertType = .logout

case .withdrawButtonDidTap:
state.alertType = .withdraw

case .confirmButtonDidTap:
state.alertType == .logout ? useCase.logout() : useCase.revokeUser()
}
}

func cancelAction() {
isPresented = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ import DSKit

struct MyPageButton: View {

@ObservedObject var viewModel: MyPageViewModel

var buttonType: MyPageButtonType

var body: some View {
ZStack {
HStack() {
if let image = viewModel.getButtonImage(type: buttonType) {
if let image = buttonType.imageName {
Image(image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
.padding(.trailing, 15)
}
Text(viewModel.getButtonTitle(type: buttonType))
Text(buttonType.titleText)
.font(.text5_medium_16)
Spacer()
Image(uiImage: buttonType == .travel ? DSKitAsset.chevrongray.image : DSKitAsset.chevronRight.image)
Expand All @@ -36,8 +34,7 @@ struct MyPageButton: View {
}
.background(DSKitAsset.blackground.swiftUIColor)
.onTapGesture {
viewModel.myPageButtonClick(type: buttonType)
buttonType.clickAction
}
}
}

Loading

0 comments on commit ea0ddfc

Please sign in to comment.