Skip to content

Commit

Permalink
fix #95 : 잔버그 수정
Browse files Browse the repository at this point in the history
.
  • Loading branch information
enebin committed Sep 19, 2023
1 parent 533c491 commit f70a4d5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 49 deletions.
Binary file modified Encrypted/Secrets/GoogleService-Info.plist.encrypted
Binary file not shown.
Binary file modified Encrypted/XCConfig/App/DEV.xcconfig.encrypted
Binary file not shown.
Binary file modified Encrypted/XCConfig/App/PROD.xcconfig.encrypted
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public struct DailyTestListFeature: Reducer {
case .fetchDailyStatistics:
return .run { [testId = state.testData.testId] send in
let dailyStatisticsData = try await network.request(.test(.statistics(testId)), object: StatisticsDTO.self)
// let dailyStatisticsData = try await network.requestWithSampleData(.test(.statistics(testId)), object: StatisticsDTO.self)
let dailyStatistics = dailyStatisticsData.toDailyStatisticsModel()
await send(.saveDailyStatistics(dailyStatistics))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ extension DailyTestListView {

extension DailyTestListView {
func statisticsScoreText(score: Double?) -> some View {
Text.keyme(score != nil ? "평균점수 | \(String(describing: score))" : "아직 아무도 풀지 않았어요",
font: .body4)
.foregroundColor(.white.opacity(0.5))
let text: String
if let score {
text = "평균점수 | \(score)"
} else {
text = "아직 아무도 풀지 않았어요"
}

return Text.keyme(text, font: .body4)
.foregroundColor(.white.opacity(0.5))
}
}
49 changes: 38 additions & 11 deletions Projects/Features/Sources/Home/HomeFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public struct HomeFeature: Reducer {
case saveIsSolved(Bool)
case saveTestId(Int)
case showTestStartView(testData: KeymeTestsModel)
case showTestResultView(testData: KeymeTestsModel)
case showErrorAlert(HomeFeatureError)

case alert(PresentationAction<Alert>)
Expand All @@ -59,11 +60,19 @@ public struct HomeFeature: Reducer {

public enum HomeFeatureError: LocalizedError {
case cannotGetAuthorizationInformation
case cannotGenerateTestLink
case network

public var errorDescription: String? {
switch self {
case .cannotGetAuthorizationInformation:
return "로그인 정보를 불러올 수 없습니다. 다시 로그인을 진행해주세요."

case .cannotGenerateTestLink:
return "링크를 생성할 수 없습니다. 잠시 후 다시 시도해주세요."

case .network:
return ""
}
}
}
Expand All @@ -77,11 +86,19 @@ public struct HomeFeature: Reducer {
case .fetchDailyTests:
return .run { send in
let fetchedTest = try await network.request(.test(.daily), object: KeymeTestsDTO.self)
// let fetchedTest = try await network.requestWithSampleData(.test(.onboarding), object: KeymeTestsDTO.self)

let testData = fetchedTest.toKeymeTestsModel()
await send(.saveIsSolved(fetchedTest.data.testResultId != nil))

await send(.saveIsSolved(fetchedTest.isSolved))
await send(.saveTestId(testData.testId))
await send(.showTestStartView(testData: testData))

if !fetchedTest.isSolved {
await send(.showTestStartView(testData: testData))
} else {
await send(.showTestResultView(testData: testData))
}
} catch: { _, send in
await send(.showErrorAlert(.network))
}

case let .saveIsSolved(isSolved):
Expand All @@ -101,19 +118,28 @@ public struct HomeFeature: Reducer {
testData: testData,
authorizationToken: authorizationToken
)

case .showTestResultView(let testData):
state.view.dailyTestId = testData.testId
guard let authorizationToken = state.authorizationToken else {
return .send(.showErrorAlert(.cannotGetAuthorizationInformation))
}

state.dailyTestListState =
DailyTestListFeature.State(
state.dailyTestListState = DailyTestListFeature.State(
testData: testData
)

case .showErrorAlert(let error):
if case .cannotGetAuthorizationInformation = error {
state.alertState = AlertState.errorWithMessage(
error.localizedDescription,
actions: {
ButtonState(action: .error(.cannotGetAuthorizationInformation), label: { TextState("닫기") })
})
if case .network = error {
state.alertState = .errorWhileNetworking
return .none
}

state.alertState = AlertState.errorWithMessage(
error.localizedDescription,
actions: {
ButtonState(action: .error(.cannotGetAuthorizationInformation), label: { TextState("닫기") })
})
return .none

case .alert(.presented(.error(let error))):
Expand All @@ -128,6 +154,7 @@ public struct HomeFeature: Reducer {

return .none
}
.ifLet(\.$alertState, action: /Action.alert)
.ifLet(\.$startTestState, action: /Action.startTest) {
StartTestFeature()
}
Expand Down
7 changes: 6 additions & 1 deletion Projects/Features/Sources/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ extension HomeView {
.frame(height: 60)
.onTapGesture {
Task {
guard let testId = viewStore.testId else {
viewStore.send(.showErrorAlert(.cannotGenerateTestLink))
return
}

if viewStore.isSolvedDailyTest {
let url = "https://keyme-frontend.vercel.app/test/\(viewStore.testId)"
let url = "https://keyme-frontend.vercel.app/test/\(testId)"
let shortURL = try await shortURLAPIManager.request(
.shortenURL(longURL: url),
object: BitlyResponse.self).link
Expand Down
6 changes: 3 additions & 3 deletions Projects/Features/Sources/Onboarding/OnboardingFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ public struct OnboardingFeature: Reducer {
state.isButtonShown = false

case .lottieEnded:
state.isButtonShown = true

if state.lottieType == .splash3 {
state.lottieType = .question
state.isLoop = true
return .run { send in
await send(.fetchOnboardingTests(
TaskResult { try await self.keymeTestsClient.fetchOnboardingTests()
}
TaskResult { try await self.keymeTestsClient.fetchOnboardingTests() }
))
}
} else {
state.isButtonShown = true
state.isLoop = true
}

Expand Down
63 changes: 34 additions & 29 deletions Projects/Features/Sources/Onboarding/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Core
import DSKit

public struct OnboardingView: View {
@EnvironmentObject var webViewSetup: KeymeWebViewSetup
@StateObject var webViewSetup = KeymeWebViewSetup()

private let store: StoreOf<OnboardingFeature>

Expand Down Expand Up @@ -104,38 +104,43 @@ public struct OnboardingView: View {

Spacer()

if viewStore.lottieType == .question {
Color.clear
.contentShape(Circle())
.onTapGesture {
HapticManager.shared.boong()
viewStore.send(.startButtonDidTap)
}
}

Spacer()

ZStack {
Rectangle()
.cornerRadius(16)
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)

Text("다음")
.font(Font(DSKitFontFamily.Pretendard.bold.font(size: 18)))
.foregroundColor(.black)
}
.onTapGesture {
HapticManager.shared.boong()
viewStore.send(.nextButtonDidTap)
}
.padding(Padding.insets(leading: 16, trailing: 16))
.frame(height: 60)
.opacity(viewStore.isButtonShown ? 1.0 : 0.0)
.animation(Animation.customInteractiveSpring(), value: viewStore.isButtonShown)
actionButton(for: viewStore.lottieType)
.onTapGesture {
HapticManager.shared.boong()
viewStore.send(
viewStore.lottieType == .question ? .startButtonDidTap : .nextButtonDidTap
)
}
.padding(Padding.insets(leading: 16, trailing: 16))
.frame(height: 60)
.opacity(viewStore.isButtonShown ? 1.0 : 0.0)
.animation(Animation.customInteractiveSpring(), value: viewStore.isButtonShown)

Spacer()
.frame(height: 54)
}
.frame(maxWidth: .infinity)
}
}

private extension OnboardingView {
func actionButton(for lottieType: LottieType) -> some View {
let buttonText: String
switch lottieType {
case .splash1, .splash2, .splash3:
buttonText = "다음"
case .question:
buttonText = "시작하기"
}

return ZStack {
Rectangle()
.cornerRadius(16)
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)

Text(buttonText)
.font(Font(DSKitFontFamily.Pretendard.bold.font(size: 18)))
.foregroundColor(.black)
}
}
}
4 changes: 4 additions & 0 deletions Projects/Network/Sources/DTO/KeymeTestsDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public struct KeymeTestsDTO: Codable {
let questionId: Int
let title: String
}

public var isSolved: Bool {
data.testResultId != nil
}
}

public struct Category: Codable {
Expand Down
2 changes: 1 addition & 1 deletion Projects/Network/Sources/DTO/StatisticsDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct StatisticsDTO: Codable {
public let data: StatisticsData

public struct StatisticsData: Codable {
public let averageRate: Int?
public let averageRate: Double?
public let questionsStatistics: [QuestionsStatisticsData]
public let solvedCount: Int
}
Expand Down

0 comments on commit f70a4d5

Please sign in to comment.