Skip to content

Commit

Permalink
fix: 설정에 프로필 정보 변경 화면 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
enebin committed Oct 2, 2023
1 parent c77e1a9 commit c5f04c3
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 80 deletions.
25 changes: 20 additions & 5 deletions Projects/Features/Sources/MainPage/MainPageFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import StoreKit
import ComposableArchitecture
import Core

Expand Down Expand Up @@ -40,22 +41,33 @@ public struct MainPageFeature: Reducer {
public init(userId: Int, testId: Int, nickname: String) {
@Dependency(\.environmentVariable) var environmentVariable
@Dependency(\.userStorage) var userStorage
let currentLaunchCount = userStorage.launchCount ?? 0
let currentLaunchCount = userStorage.launchCount ?? 0 // 실행한 적 없으면 nil == 0

environmentVariable.userId = userId
environmentVariable.nickname = nickname

self._home = .init(.init(userId: userId, nickname: nickname, testId: testId))
self._myPage = .init(.init(userId: userId, nickname: nickname, testId: testId))

// if currentLaunchCount == 0 {
print("[KEYME] Keyme launched \(currentLaunchCount) times")
if currentLaunchCount == 0 {
onboardingGuideState = OnboardingGuideFeature.State()
// } else if currentLaunchCount == 3 {
// // Request review
// }
} else if currentLaunchCount == 3 {
// Request review
requestReview()
}

userStorage.launchCount = currentLaunchCount + 1
}

/// 앱스토어 리뷰 요청하는 뷰 띄우기
private func requestReview() {
DispatchQueue.main.async {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
SKStoreReviewController.requestReview(in: windowScene)
}
}
}
}

public enum Action {
Expand Down Expand Up @@ -83,6 +95,9 @@ public struct MainPageFeature: Reducer {

// testId =

case .onboardingGuide(.presented(.dismiss)):
state.onboardingGuideState = nil

default:
break
}
Expand Down
1 change: 0 additions & 1 deletion Projects/Features/Sources/MyPage/MyPageFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public struct MyPageFeature: Reducer {
return .none

case .view(.prepareSettingView):
print("@@ init from mypage")
state.settingViewState = SettingFeature.State()
return .none

Expand Down
103 changes: 52 additions & 51 deletions Projects/Features/Sources/Onboarding/Guide/OnboardingGuideView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import SwiftUI

public struct OnboardingGuideFeature: Reducer {
public struct State: Equatable {}
public enum Action: Equatable {}
public enum Action: Equatable {
case dismiss
}

public var body: some ReducerOf<Self> {
Reduce { state, action in
Expand All @@ -39,73 +41,72 @@ struct OnboardingGuideView: View {
}

var body: some View {
VStack {
Group {
if !isLastPage {
topBar {

WithViewStore(store, observe: { $0 }) { viewStore in
VStack {
Group {
if !isLastPage {
topBar(dismissAction: {
viewStore.send(.dismiss)
})
} else {
EmptyView()
}
} else {
EmptyView()
}
}
.transition(.opacity)
.padding(.horizontal, 16)
.padding(.top, 30)

Spacer()

TabView(selection: $currentTabIndex) {
ForEach(0..<images.count, id: \.self) { index in
let guideImage = images[index]

guideImage.image
.modifyForGuideView()
.tag(index)
.transition(.opacity)
.padding(.horizontal, 16)
.padding(.top, 30)
Spacer()
TabView(selection: $currentTabIndex) {
ForEach(0..<images.count, id: \.self) { index in
let guideImage = images[index]
guideImage.image
.modifyForGuideView()
.tag(index)
}
}
}
.tabViewStyle(.page(indexDisplayMode: .always))

Group {
if isLastPage {
Button(action: {
HapticManager.shared.boong()
}) {
HStack {
Spacer()
Text.keyme("시작해볼까요?", font: .body2).frame(height: 60)
Spacer()
.tabViewStyle(.page(indexDisplayMode: .always))

Group {
if isLastPage {
Button(action: {
HapticManager.shared.boong()
viewStore.send(.dismiss)
}) {
HStack {
Spacer()
Text.keyme("시작해볼까요?", font: .body2).frame(height: 60)
Spacer()
}
}
.foregroundColor(.black)
.background(.white)
.cornerRadius(16)
.padding(.horizontal, 16)
.padding(.bottom, 20)
} else {
Spacer().frame(height: 60)
}
.foregroundColor(.black)
.background(.white)
.cornerRadius(16)
.padding(.horizontal, 16)
.padding(.bottom, 20)
} else {
Spacer().frame(height: 60)
}
.transition(.opacity)
}
.transition(.opacity)
.background(DSKitAsset.Color.keymeBlack.swiftUIColor)
.animation(Animation.customInteractiveSpring(), value: currentTabIndex)
}
.background(DSKitAsset.Color.keymeBlack.swiftUIColor)
.animation(Animation.customInteractiveSpring(), value: currentTabIndex)
}

private func topBar(action: @escaping () -> Void) -> some View {
private func topBar(dismissAction: @escaping () -> Void) -> some View {
HStack {
Button(action: { }) {
Button(action: dismissAction) {
Text.keyme("건너뛰기", font: .body4)
}

Spacer()

Button(action: {
print(images.endIndex)
guard !isLastPage else {
return
}

guard !isLastPage else { return }
currentTabIndex += 1
}) {
Text.keyme("다음 >", font: .body4)
Expand Down
28 changes: 25 additions & 3 deletions Projects/Features/Sources/Registration/RegisterFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public struct RegistrationFeature: Reducer {
public init() {}

public struct State: Equatable {
@PresentationState var alertState: AlertState<Action.Alert>?

/// 온보딩에서 쓰는 게 아니라 마이페이지에서 쓸 거라면 `true`를
var isForMyPage = false

var status: Status = .notDetermined
var isNicknameAvailable: Bool?
var canRegister: Bool {
Expand All @@ -35,6 +40,10 @@ public struct RegistrationFeature: Reducer {
case needsRegister
case complete
}

public init(isForMyPage: Bool = false) {
self.isForMyPage = isForMyPage
}
}

public enum Action: Equatable {
Expand All @@ -48,6 +57,11 @@ public struct RegistrationFeature: Reducer {

case finishRegister(nickname: String, thumbnailURL: URL?, originalImageURL: URL?)
case finishRegisterResponse(MemberUpdateDTO)

case alert(PresentationAction<Alert>)
case showAlert

public enum Alert: Equatable {}
}

public var body: some Reducer<State, Action> {
Expand All @@ -72,7 +86,6 @@ public struct RegistrationFeature: Reducer {
}
}

// MARK: checkDuplicatedNickname
case .checkDuplicatedNickname(let nickname):
return .run(priority: .userInitiated) { send in
let result = try await network.request(
Expand All @@ -86,7 +99,6 @@ public struct RegistrationFeature: Reducer {
case .checkDuplicatedNicknameResponse(let isNicknameDuplicated):
state.isNicknameAvailable = isNicknameDuplicated

// MARK: registerProfileImage
case .registerProfileImage(let imageData):
return .run { send in
let result = try await network.request(
Expand All @@ -108,7 +120,6 @@ public struct RegistrationFeature: Reducer {
state.thumbnailURL = thumnailURL
state.originalImageURL = originalImageURL

// MARK: finishRegister
case .finishRegister(let nickname, let thumbnailURL, let originalImageURL):
return .run { send in
let result = try await network.request(
Expand All @@ -119,13 +130,24 @@ public struct RegistrationFeature: Reducer {
object: MemberUpdateDTO.self)

await send(.finishRegisterResponse(result))
} catch: { _, send in
await send(.showAlert)
}

case .finishRegisterResponse:
state.status = .complete

// MARK: - Child actions:
case .showAlert:
state.alertState = .errorWhileNetworking

case .alert:
return .none

}

return .none
}
.ifLet(\.$alertState, action: /Action.alert)
}
}
29 changes: 15 additions & 14 deletions Projects/Features/Sources/Registration/RegistrationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct RegistrationView: View {
public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
VStack(spacing: 0) {
Text.keyme("회원가입", font: .body3Semibold)
Text.keyme(viewStore.isForMyPage ? "프로필 변경" : "회원가입", font: .body3Semibold)
.foregroundColor(.white)
.padding(.top, 16)
.padding(.bottom, 24)
Expand All @@ -48,7 +48,6 @@ public struct RegistrationView: View {
Task(priority: .utility) {
guard let imageData = try await newImage?.loadTransferable(type: Data.self) else {
// TODO: Throw error and show alert
print("IMAGE ERROR")
return
}

Expand Down Expand Up @@ -105,17 +104,19 @@ public struct RegistrationView: View {
Spacer(minLength: 50)

// 닉네임 관련 안내메세지
Rectangle()
.frame(height: 80)
.foregroundColor(
DSKitAsset.Color.keymeBlack.swiftUIColor.opacity(0.8))
.cornerRadius(8)
.overlay(
Text.keyme("친구들이 원활하게 문제를 풀 수 있도록, 나를 가장 잘 나타내는 닉네임으로 설정해주세요.", font: .body4)
.lineSpacing(10)
.foregroundColor(.white)
)
.padding(.bottom, 64)
if viewStore.isForMyPage == false {
Rectangle()
.frame(height: 80)
.foregroundColor(
DSKitAsset.Color.keymeBlack.swiftUIColor.opacity(0.8))
.cornerRadius(8)
.overlay(
Text.keyme("친구들이 원활하게 문제를 풀 수 있도록, 나를 가장 잘 나타내는 닉네임으로 설정해주세요.", font: .body4)
.lineSpacing(10)
.foregroundColor(.white)
)
.padding(.bottom, 64)
}

// 다음 페이지로 넘어가기 위한 Button
Button(action: {
Expand All @@ -129,7 +130,7 @@ public struct RegistrationView: View {
HStack {
Spacer()

Text("다음")
Text(viewStore.isForMyPage ? "완료" : "다음")
.font(.system(size: 18))
.fontWeight(.bold)
.frame(height: 60)
Expand Down
Loading

0 comments on commit c5f04c3

Please sign in to comment.