Skip to content

Commit

Permalink
feat: 제출 로직 활성화
Browse files Browse the repository at this point in the history
  • Loading branch information
enebin committed Aug 18, 2023
1 parent 2a3ccf8 commit 066058e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ public struct KeymeTestsFeature: Reducer {

public struct State: Equatable {
let url: String
var shouldCloseWindow: Bool = false

public init(url: String) {
self.url = url
}
}

public enum Action {
public enum Action: Equatable {
case transition
case close
case submit(resultCode: String, testResultId: Int)
case showResult(data: String)
}

public init() { }
Expand All @@ -30,6 +34,12 @@ public struct KeymeTestsFeature: Reducer {
switch action {
case .transition:
return .none
case .close:
return .none
case .submit(let code, let id):
return .none
case .showResult(let data):
return .none
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct KeymeTestsView: View {
print("close")
}
.onTestSubmitted { testResultId in
print(testResultId)
viewStore.send(.showResult(data: "\(testResultId)"))
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Expand Down
27 changes: 19 additions & 8 deletions Projects/Features/Sources/Onboarding/OnboardingFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,34 @@ public enum LottieType: CaseIterable {
public struct OnboardingFeature: Reducer {
public enum Status: Equatable {
case notDetermined
case completed
case needsOnboarding
case completed
}

public struct State: Equatable {
@PresentationState public var keymeTestsState: KeymeTestsFeature.State?
public var status: Status = .notDetermined

public var keymeTests: KeymeTestsFeature.State?
public var testId: Int = 0
public var lottieType: LottieType = .splash1
public var lottieIdx: Int = 0
public var isButtonShown: Bool = false
public var isLoop: Bool = false
public var isBlackBackground: Bool = false

public var resultData: String?

public init() { }
}

public enum Action: Equatable {
case keymeTests(PresentationAction<KeymeTestsFeature.Action>)
case fetchOnboardingTests(TaskResult<KeymeTestsModel>)
case nextButtonDidTap
case lottieEnded
case startButtonDidTap
case keymeTests(KeymeTestsFeature.Action)

case showResult(data: String)
case succeeded
case failed
}
Expand Down Expand Up @@ -114,20 +117,28 @@ public struct OnboardingFeature: Reducer {
return .none

case .startButtonDidTap:
let url = "https://keyme-frontend.vercel.app/test/\(state.testId)?nickname=키미"
state.keymeTests = KeymeTestsFeature.State(url: url)
let url = "https://keyme-frontend.vercel.app/test/\(5)?nickname=키미" // TODO:
state.keymeTestsState = KeymeTestsFeature.State(url: url)

case .keymeTests:
return .none
case .keymeTests(.presented(.showResult(let data))):
return .send(.showResult(data: data))

case .showResult(data: let data):
state.resultData = data

case .succeeded, .failed:
return .none

case .keymeTests(.dismiss):
break

default:
break
}

return .none
}
.ifLet(\.keymeTests, action: /Action.keymeTests) {
.ifLet(\.$keymeTestsState, action: /Action.keymeTests) {
KeymeTestsFeature()
}
}
Expand Down
65 changes: 35 additions & 30 deletions Projects/Features/Sources/Onboarding/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,44 @@ public struct OnboardingView: View {
public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
ZStack {
IfLetStore(
self.store.scope(
state: \.keymeTests,
action: OnboardingFeature.Action.keymeTests
),
then: { store in
KeymeTestsView(store: store)
.ignoresSafeArea(.all)
.transition(.scale.animation(.easeIn))
},
else: {
KeymeLottieView(asset: AnimationAsset.background,
loopMode: .loop)

if viewStore.isBlackBackground {
Rectangle()
.foregroundColor(DSKitAsset.Color.keymeBlack.swiftUIColor)
} else {
BackgroundBlurringView(style: .systemMaterialDark)
}

if viewStore.isLoop {
KeymeLottieView(asset: viewStore.lottieType.lottie,
if let resultData = viewStore.resultData {
Text("Done")
.foregroundColor(.white)
} else {
IfLetStore(
self.store.scope(
state: \.$keymeTestsState,
action: OnboardingFeature.Action.keymeTests
),
then: { store in
KeymeTestsView(store: store)
.ignoresSafeArea(.all)
.transition(.scale.animation(.easeIn))
},
else: {
KeymeLottieView(asset: AnimationAsset.background,
loopMode: .loop)
} else {
KeymeLottieView(asset: viewStore.lottieType.lottie) {
viewStore.send(.lottieEnded)

if viewStore.isBlackBackground {
Rectangle()
.foregroundColor(DSKitAsset.Color.keymeBlack.swiftUIColor)
} else {
BackgroundBlurringView(style: .systemMaterialDark)
}

if viewStore.isLoop {
KeymeLottieView(asset: viewStore.lottieType.lottie,
loopMode: .loop)
} else {
KeymeLottieView(asset: viewStore.lottieType.lottie) {
viewStore.send(.lottieEnded)
}
}

splashView(viewStore)
}

splashView(viewStore)
}
)
)
}
}
.background(DSKitAsset.Color.keymeBlack.swiftUIColor)
.ignoresSafeArea()
Expand Down
9 changes: 2 additions & 7 deletions Projects/Features/Sources/Root/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public struct RootView: View {
IfLetStore(loginStore) { store in
SignInView(store: store)
}
}
else if viewStore.onboardingStatus?.status == .notDetermined {
} else if viewStore.onboardingStatus?.status == .notDetermined {
// 온보딩 상태를 로딩 중
ProgressView()
} else if viewStore.onboardingStatus?.status == .needsOnboarding {
Expand All @@ -48,15 +47,11 @@ public struct RootView: View {
IfLetStore(onboardingStore) { store in
OnboardingView(store: store)
}
}
else {
} else {
// 가입했고 온보딩을 진행한 유저
KeymeMainView(store: Store(
initialState: MainPageFeature.State(),
reducer: MainPageFeature()))
.onAppear {
print("@@", viewStore.logInStatus, viewStore.onboardingStatus)
}
}
}
}
Expand Down

0 comments on commit 066058e

Please sign in to comment.