Skip to content

Commit

Permalink
[Refactor/#84] State 구조체 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Sep 3, 2024
1 parent 38ec1c0 commit 56048c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import DSKit

struct MyPageButton_Refactor: View {

@ObservedObject var viewModel: MyPageViewModel_Refactor

var buttonType: MyPageButtonType_Refactor

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import SwiftUI

import Combine

import Core
Expand All @@ -21,26 +20,34 @@ class MyPageViewModel_Refactor: ObservableObject {
self.container = container
}

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

//MARK: Action

enum Action {
case getUserData
case revokeUser
case logout
}

struct State {
var alertType: CustomAlertType
var name: String
var point: Int
}

func send(action: Action) {
switch action {
case .getUserData:
container.services.userService.getUserData()
.sink { _ in
.sink { _ in
} receiveValue: { [weak self] data in
self?.name = data.data?.name ?? ""
self?.point = data.data?.point ?? 0
self?.state.name = data.data?.name ?? ""
self?.state.point = data.data?.point ?? 0
}.store(in: cancelBag)

case .revokeUser:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import DSKit
import Core

public struct MyPageView_Refactor: View {


@State private var isPresented: Bool = false
@StateObject var viewModel: MyPageViewModel_Refactor

Expand Down Expand Up @@ -73,15 +71,13 @@ extension MyPageView_Refactor {
Image(uiImage: DSKitAsset.profile.image)
.frame(width: 54, height: 54)
.padding(10)
//TODO: 서버통신이랑 이어지는 부분이라서
Text(viewModel.name)
.font(.title4_semibold_20)
Spacer()
.frame(height: 16)
HStack {
Text(StringLiteral.MyPageAccountControl.point)
.font(.text6_medium_14)
//TODO: 서버통신이랑 이어지는 부분이라서
Text("\(viewModel.point)")
.font(.text6_medium_14)
}
Expand All @@ -95,8 +91,8 @@ extension MyPageView_Refactor {
}
private func MyInfoView() -> some View {
VStack(spacing: 0) {
MyPageButton_Refactor(viewModel: viewModel, buttonType: .travel)
MyPageButton_Refactor(viewModel: viewModel, buttonType: .market)
MyPageButton_Refactor(buttonType: .travel)
MyPageButton_Refactor(buttonType: .market)
}
.background(DSKitAsset.gray7.swiftUIColor)
}
Expand All @@ -106,8 +102,8 @@ extension MyPageView_Refactor {
.font(.text4_semibold_16)
.foregroundColor(DSKitAsset.gray2.swiftUIColor)
.padding(.vertical, 14)
MyPageButton_Refactor(viewModel: viewModel, buttonType: .info)
MyPageButton_Refactor(viewModel: viewModel, buttonType: .term)
MyPageButton_Refactor(buttonType: .info)
MyPageButton_Refactor(buttonType: .term)
}
}
private func AccountControlView() -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class StubAuthService: AuthServiceType {
func revokeUser() -> AnyPublisher<EmptyResponseDTO, Error> {
Empty().eraseToAnyPublisher()
}

func logoutUser() -> AnyPublisher<EmptyResponseDTO, Error> {
Empty().eraseToAnyPublisher()
}
Expand Down

0 comments on commit 56048c9

Please sign in to comment.