Skip to content

Commit

Permalink
feat #21: 데일리 문제 풀이 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn authored and enebin committed Aug 17, 2023
1 parent 3c9585a commit f64cc33
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
7 changes: 4 additions & 3 deletions Projects/Domain/Sources/Client/KeymeTestsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import ComposableArchitecture
import Domain

public struct KeymeTestsStartFeature: Reducer {

public struct State: Equatable {
public var isAnimating: Bool = false
public var isOnboarding: Bool
public var nickname: String?
public var icons: [IconModel] = []
public var icon: IconModel = .EMPTY

public init(isOnboarding: Bool) {
self.isOnboarding = isOnboarding
Expand All @@ -27,25 +28,17 @@ public struct KeymeTestsStartFeature: Reducer {
case fetchOnboardingTests(TaskResult<KeymeTestsModel>)
case fetchDailyTests(TaskResult<KeymeTestsModel>)
case startTests
case setIcon(IconModel)
}

@Dependency(\.continuousClock) var clock
@Dependency(\.keymeTestsClient) var keymeTestsClient

public init() { }

public var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case let .fetchOnboardingTests(.success(tests)):
state.nickname = tests.nickname
state.icons = tests.icons
case .fetchOnboardingTests(.failure):
state.nickname = nil
case let .fetchDailyTests(.success(tests)):
state.nickname = tests.nickname
state.icons = tests.icons
case .fetchDailyTests(.failure):
state.nickname = nil
case .viewWillAppear:
if state.isOnboarding {
return .run { send in
Expand All @@ -60,8 +53,26 @@ public struct KeymeTestsStartFeature: Reducer {
))
}
}
case let .fetchOnboardingTests(.success(tests)),
let .fetchDailyTests(.success(tests)):
state.nickname = tests.nickname
state.isAnimating.toggle()
return .run { send in
repeat {
for icon in tests.icons {
await send(.setIcon(icon))
try await self.clock.sleep(for: .seconds(1.59))
}
} while true
}
case .fetchOnboardingTests(.failure),
.fetchDailyTests(.failure):
state.nickname = nil
case .startTests:
// TODO: 웹뷰 구현
return .none
case let .setIcon(icon):
state.icon = icon
}
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Util
import DSKit

public struct KeymeTestsStartView: View {
@State private var isAnimation = false
public var store: StoreOf<KeymeTestsStartFeature>

public init(store: StoreOf<KeymeTestsStartFeature>) {
Expand Down Expand Up @@ -50,7 +49,7 @@ public struct KeymeTestsStartView: View {
}

func logoImage() -> some View {
#warning("로고로 이미지 변경 필요")
// TODO: 로고로 이미지 변경 필요
return Image(systemName: "eyes.inverse")
.frame(width: 30, height: 30)
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor)
Expand All @@ -70,29 +69,26 @@ public struct KeymeTestsStartView: View {
Circle()
.strokeBorder(.white.opacity(0.3), lineWidth: 1)
.background(Circle().foregroundColor(.white.opacity(0.3)))
.frame(width: isAnimation ? 230 : 180, height: isAnimation ? 230 : 180)
.frame(width: 280, height: 280)
.scaleEffect(viewStore.isAnimating ? 1 : 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(Color.hex(viewStore.state.icons.first?.color ?? ""))
.frame(width: isAnimation ? 110 : 0, height: isAnimation ? 110 : 0)
.foregroundColor(viewStore.icon.color)
.frame(width: 110, height: 110)
.scaleEffect(viewStore.isAnimating ? 1 : 0)
.animation(.spring(response: 0.8).repeatForever(), value: viewStore.isAnimating)

viewStore.state.icons.first?.image.toImage()
.frame(width: isAnimation ? 30 : 0, height: isAnimation ? 30 : 0)
}
.onAppear {
withAnimation(
.easeIn(duration: 0.5)
.delay(0.3)
.repeatForever(autoreverses: true)
) {
isAnimation.toggle()
}
KFImageManager.shared.toImage(url:viewStore.icon.image)
.frame(width: 24, height: 24)
.scaleEffect(viewStore.isAnimating ? 1 : 0)
.animation(.spring(response: 0.8).repeatForever(), value: viewStore.isAnimating)
}
}
}

#warning("Util로 이동")
//TODO: Util로 이동
extension EdgeInsets {
static func insets(top: CGFloat=0, leading: CGFloat=0, bottom: CGFloat=0, trailing: CGFloat=0) -> EdgeInsets {
return EdgeInsets(top: top, leading: leading, bottom: bottom, trailing: trailing)
Expand Down
6 changes: 1 addition & 5 deletions Projects/Keyme/Sources/KeymeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ struct KeymeApp: App {

var body: some Scene {
WindowGroup {
// RootView()
KeymeTestsStartView(store: Store(
initialState: KeymeTestsStartFeature.State(isOnboarding: true),
reducer: KeymeTestsStartFeature()
))
RootView()
}
}
}
Expand Down

0 comments on commit f64cc33

Please sign in to comment.