Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[온보딩] 결과 페이지 #72

Merged
merged 18 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x3A",
"green" : "0x3A",
"red" : "0x3A"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x3A",
"green" : "0x3A",
"red" : "0x3A"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Group 4487407.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion Projects/Domain/Sources/Client/KeymeTestsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Network
public struct KeymeTestsClient {
public var fetchOnboardingTests: @Sendable () async throws -> KeymeTestsModel
public var fetchDailyTests: @Sendable () async throws -> KeymeTestsModel
public var fetchTestResult: @Sendable (Int) async throws -> [TestResultModel]
public var postTestResult: @Sendable (String) async throws -> String
}

extension DependencyValues {
Expand All @@ -32,10 +34,22 @@ extension KeymeTestsClient: DependencyKey {
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.requestWithSampleData(api, object: KeymeTestsDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: KeymeTestsDTO.self)

return response.toIconModel()
}, fetchTestResult: { testResultId in
let api = KeymeTestsAPI.result(testResultId)
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: TestResultDTO.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: TestResultDTO.self)

return response.data.results.map { $0.toModel() }
}, postTestResult: { resultCode in
let api = KeymeTestsAPI.register(resultCode)
// var response = try await KeymeTestsAPIManager.shared.requestWithSampleData(api, object: BaseDTO<String>.self)
var response = try await KeymeTestsAPIManager.shared.request(api, object: BaseDTO<String>.self)

return response.message
}
)
}
2 changes: 1 addition & 1 deletion Projects/Domain/Sources/Model/KeymeTestsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct KeymeTestsModel: Equatable {
public let icons: [IconModel]
}

public struct IconModel: Equatable {
public struct IconModel: Equatable, Hashable {
public let image: String
public let color: Color

Expand Down
15 changes: 15 additions & 0 deletions Projects/Domain/Sources/Model/KeymeWebModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// KeymeWebViewModel.swift
// Domain
//
// Created by 김영인 on 2023/08/18.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import Foundation

public struct KeymeWebViewModel: Codable, Equatable {
public let matchRate: Int
public let resultCode: String
public let testResultId: Int
}
34 changes: 34 additions & 0 deletions Projects/Domain/Sources/Model/TestResultModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// TestResultModel.swift
// Domain
//
// Created by 김영인 on 2023/08/18.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import SwiftUI

import Network

public struct TestResultModel: Equatable, Hashable {
public let title: String
public let nickname: String = "키미" // TODO: 추후에 수정
public let score: Int
public let icon: IconModel

public static let EMPTY: TestResultModel = .init(
title: "",
score: 0,
icon: IconModel.EMPTY)
}

public extension ResultDTO {
func toModel() -> TestResultModel {
return TestResultModel(
title: keyword,
score: score,
icon: IconModel(image: category.iconUrl,
color: Color.hex(category.color))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ComposableArchitecture
import Domain

public struct KeymeTestsStartFeature: Reducer {

public struct State: Equatable {
public var keymeTests: KeymeTestsFeature.State?
public var isAnimating: Bool = false
Expand Down Expand Up @@ -45,6 +44,7 @@ public struct KeymeTestsStartFeature: Reducer {
TaskResult { try await self.keymeTestsClient.fetchDailyTests() }
))
}

case let .fetchDailyTests(.success(tests)):
state.nickname = tests.nickname
state.testId = tests.testId
Expand All @@ -57,16 +57,21 @@ public struct KeymeTestsStartFeature: Reducer {
}
} while true
}

case .fetchDailyTests(.failure):
state.nickname = nil

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public struct KeymeTestsStartView: View {
.frame(width: 280, height: 280)
.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)
.animation(.spring(response: 0.82).repeatForever(), value: viewStore.isAnimating)

Circle()
.foregroundColor(viewStore.icon.color)
Expand All @@ -84,7 +84,8 @@ public struct KeymeTestsStartView: View {
.animation(.spring(response: 0.8).repeatForever(), value: viewStore.isAnimating)

KFImageManager.shared.toImage(url:viewStore.icon.image)
.frame(width: 24, height: 24)
.frame(width: 30, height: 30)
.scaledToFit()
.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 @@ -7,7 +7,9 @@
//

import ComposableArchitecture
import Foundation

import Domain
import Network

public struct KeymeTestsFeature: Reducer {

Expand All @@ -23,9 +25,12 @@ public struct KeymeTestsFeature: Reducer {
case transition
case close
case submit(resultCode: String, testResultId: Int)
case showResult(data: String)
case showResult(data: KeymeWebViewModel)
case postResult(TaskResult<String>)
}

@Dependency(\.keymeTestsClient) var keymeTestsClient

public init() { }

public var body: some Reducer<State, Action> {
Expand All @@ -38,6 +43,14 @@ public struct KeymeTestsFeature: Reducer {
case .submit(let code, let id):
return .none
case .showResult(let data):
return .run { [resultCode = data.resultCode] send in
await send(.postResult(
TaskResult { try await
self.keymeTestsClient.postTestResult(resultCode)
}
))
}
default:
return .none
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public struct KeymeTestsView: View {
.onCloseWebView {
print("close")
}
.onTestSubmitted { testResultId in
viewStore.send(.showResult(data: "\(testResultId)"))
.onTestSubmitted { testResult in
viewStore.send(.showResult(data: testResult))
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// CardView.swift
// Features
//
// Created by 고도현 on 2023/08/18.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import SwiftUI

// CarouselView의 카드 한 장에 해당하는 뷰
struct CardView: View {
let index: Int
let minCircleRadius: CGFloat = 210

var body: some View {
VStack(alignment: .center, spacing: 4) {
Spacer()

VStack(alignment: .leading, spacing: 8) {
Text("표현력")
.font(.system(size: 14)) // FIXME: font system으로 변경
.foregroundColor(.gray)

Text("키미미미미미님의 애정표현 정도는?")
.font(.system(size: 24)) // FIXME: font system으로 변경
.fontWeight(.bold)
.foregroundColor(.white)
.multilineTextAlignment(.leading)

Rectangle()
.frame(height: 0.3)
.foregroundColor(.hex("#FFFFFF"))

HStack {
Text("04")
.font(.system(size: 32))
.fontWeight(.bold)

Text("점")
.font(.system(size: 12))

Spacer()
}
}
.frame(width: 256)

Spacer()

HStack {
Spacer()

ZStack(alignment: .center) {
Circle() // 큰 원
.frame(width: 280, height: 280)
.foregroundColor(.hex("#3A3A3A"))
.overlay( // 큰 원의 테두리
Circle()
.stroke(
Color.hex("#3A3A3A"),
lineWidth: 1
)
)

Circle() // 작은 원
.frame(width: minCircleRadius, height: minCircleRadius)
.foregroundColor(.mint)
}

Spacer()
}

Spacer()
}
.padding() // MARGIN
.frame(width: 341, height: 491)
.background(Color.hex("#232323"))
.cornerRadius(24)
.overlay(
RoundedRectangle(cornerRadius: 24)
.stroke(
Color.hex("#3A3A3A"),
lineWidth: 1
)
)
}
}

struct KeymeCardView_Previews: PreviewProvider {
static var previews: some View {
CardView(index: 0)
}
}
Loading