Skip to content

Commit

Permalink
feat #25: 데일리 문제 풀이 웹뷰 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Aug 17, 2023
1 parent 05b2609 commit 3b70786
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 25 deletions.
5 changes: 3 additions & 2 deletions Projects/Domain/Sources/Client/KeymeTestsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ extension KeymeTestsClient: DependencyKey {
public static var liveValue = KeymeTestsClient(
fetchOnboardingTests: {
let api = KeymeTestsAPI.onboarding
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: KeymeTestsDTO.self)
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: KeymeTestsDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: KeymeTestsDTO.self)

return response.toIconModel()
}, fetchDailyTests: {
let api = KeymeTestsAPI.daily
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: KeymeTestsDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: KeymeTestsDTO.self)

return response.toIconModel()
}
)
Expand Down
5 changes: 4 additions & 1 deletion Projects/Domain/Sources/Model/KeymeTestsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Kingfisher

public struct KeymeTestsModel: Equatable {
public let nickname: String
public let testId: Int
public let icons: [IconModel]
}

Expand All @@ -31,6 +32,8 @@ public extension KeymeTestsDTO {
IconModel(image: $0.category.iconUrl,
color: Color.hex($0.category.color))
}
return KeymeTestsModel(nickname: nickname ?? "키미키미", icons: icons)
return KeymeTestsModel(nickname: nickname ?? "키미키미",
testId: data.testId,
icons: icons)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
// Copyright © 2023 team.humanwave. All rights reserved.
//

import CoreFoundation
import ComposableArchitecture

import Domain

public struct KeymeTestsStartFeature: Reducer {

public struct State: Equatable {
public var keymeTests: KeymeTestsFeature.State?
public var isAnimating: Bool = false
public var nickname: String?
public var testId: Int = 0
public var icon: IconModel = .EMPTY

public init() { }
Expand All @@ -23,8 +26,9 @@ public struct KeymeTestsStartFeature: Reducer {
public enum Action {
case viewWillAppear
case fetchDailyTests(TaskResult<KeymeTestsModel>)
case startTests
case setIcon(IconModel)
case startButtonDidTap
case keymeTests(KeymeTestsFeature.Action)
}

@Dependency(\.continuousClock) var clock
Expand All @@ -43,6 +47,7 @@ public struct KeymeTestsStartFeature: Reducer {
}
case let .fetchDailyTests(.success(tests)):
state.nickname = tests.nickname
state.testId = tests.testId
state.isAnimating.toggle()
return .run { send in
repeat {
Expand All @@ -54,13 +59,18 @@ public struct KeymeTestsStartFeature: Reducer {
}
case .fetchDailyTests(.failure):
state.nickname = nil
case .startTests:
// TODO: 웹뷰 구현
return .none
case let .setIcon(icon):
state.icon = icon
case .startButtonDidTap:
let url = "https://keyme-frontend.vercel.app/test/\(state.testId)"
state.keymeTests = KeymeTestsFeature.State(url: url)
case .keymeTests:
return .none
}
return .none
}
.ifLet(\.keymeTests, action: /Action.keymeTests) {
KeymeTestsFeature()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,33 @@ public struct KeymeTestsStartView: View {
public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
VStack {
Spacer()
.frame(height: 75)

welcomeText(viewStore)

Spacer()

startTestsButton(viewStore)

Spacer()
Spacer()
IfLetStore(
self.store.scope(
state: \.keymeTests,
action: KeymeTestsStartFeature.Action.keymeTests
),
then: { store in
KeymeTestsView(store: store)
.ignoresSafeArea(.all)
.transition(.scale.animation(.easeIn))
},
else: {
Spacer()
.frame(height: 75)

welcomeText(viewStore)

Spacer()

startTestsButton(viewStore)
.onTapGesture {
viewStore.send(.startButtonDidTap)
}

Spacer()
Spacer()
}
)
}
.frame(maxWidth: .infinity)
.onAppear {
Expand All @@ -58,19 +74,19 @@ public struct KeymeTestsStartView: View {
.strokeBorder(.white.opacity(0.3), lineWidth: 1)
.background(Circle().foregroundColor(.white.opacity(0.3)))
.frame(width: 280, height: 280)
.scaleEffect(viewStore.isAnimating ? 1 : 0.8)
.scaleEffect(viewStore.isAnimating ? 1.0 : 0.8)
.shadow(color: .white.opacity(0.3), radius: 30, x: 0, y: 10)
.animation(.spring(response: 0.85).repeatForever(), value: viewStore.isAnimating)

Circle()
.foregroundColor(viewStore.icon.color)
.frame(width: 110, height: 110)
.scaleEffect(viewStore.isAnimating ? 1 : 0)
.scaleEffect(viewStore.isAnimating ? 1.0 : 0.001)
.animation(.spring(response: 0.8).repeatForever(), value: viewStore.isAnimating)

KFImageManager.shared.toImage(url:viewStore.icon.image)
.frame(width: 24, height: 24)
.scaleEffect(viewStore.isAnimating ? 1 : 0)
.scaleEffect(viewStore.isAnimating ? 1.0 : 0.001)
.animation(.spring(response: 0.8).repeatForever(), value: viewStore.isAnimating)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public struct KeymeWebView: UIViewRepresentable {

public func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView(frame: CGRect.zero, configuration: WKWebViewConfiguration())
webView.backgroundColor = .init(white: 1, alpha: 0.3)

if let url = URL(string: url) {
webView.load(URLRequest(url: url))
Expand Down
3 changes: 2 additions & 1 deletion Projects/Network/Sources/DTO/KeymeTestsDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public struct DataDTO: Codable {
public let testResultId: Int?
public let owner: PresenterProfileDTO
public let questions: [QuestionDTO]
let solvedCount, testId: Int
let solvedCount: Int
public let testId: Int
let title: String
}

Expand Down
6 changes: 3 additions & 3 deletions Projects/Network/Sources/Network/API/KeymeTestsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension KeymeTestsAPI: BaseAPI {

public var headers: [String : String]? {
// TODO: token 받아서 넣기
return ["Authorization": "access-token"]
return ["Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhY2Nlc3NUb2tlbiIsImlhdCI6MTY5MTg0MjM1NiwiZXhwIjoxNjk0NDM0MzU2LCJtZW1iZXJJZCI6Miwicm9sZSI6IlJPTEVfVVNFUiJ9.bLUl_ObvXr2pkLGNBZYWbJgLZLo3P0xB2pawckRGYZM"]
}

public var sampleData: Data {
Expand All @@ -44,13 +44,13 @@ extension KeymeTestsAPI: BaseAPI {
"code": 200,
"message": "요청에 성공했습니다.",
"data": {
"testId": 5,
"testId": 4,
"testResultId": null,
"solvedCount": 0,
"title": "님은 돈관리를 잘한다",
"owner": {
"id": 2,
"nickname": null,
"nickname": "영인",
"profileThumbnail": "https://keyme-ec2-access-s3.s3.ap-northeast-2.amazonaws.com/keyme_default.png"
},
"questions": [
Expand Down

0 comments on commit 3b70786

Please sign in to comment.