Skip to content

Commit

Permalink
refactor: 홈 뷰 로딩 자연스럽게 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
enebin committed Sep 30, 2023
1 parent 10ae867 commit 43c4ffc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public struct DailyTestListFeature: Reducer {
return .cancel(id: CancelID.dailyTestList)

case .fetchDailyStatistics:
state.dailyStatistics = nil

return .run { [testId = state.testData.testId] send in
let dailyStatisticsData = try await network.request(
.test(.statistics(testId)), object: TestStatisticsDTO.self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ struct DailyTestListView: View {
Spacer().frame(height: bottomSpacerHeight)
}
.padding(.horizontal, horizontalPadding)
.refreshable { viewStore.send(.fetchDailyStatistics) }
.refreshable {
viewStore.send(.fetchDailyStatistics)
}
.padding(.vertical, 1)
.onAppear { viewStore.send(.onAppear) }
.onDisappear { viewStore.send(.onDisappear) }
.animation(Animation.customInteractiveSpring(), value: viewStore.dailyStatistics)
}
}

Expand Down Expand Up @@ -138,11 +141,12 @@ struct DailyTestListView: View {
}

private func loadingView() -> some View {
HStack {
Spacer()
CustomProgressView()
Spacer()
}
dailyTestList(
nickname: "NICKNAME",
dailyStatistics: StatisticsData.mockData(questionCount: 7),
onItemTapped: { _ in }
)
.redacted(reason: .placeholder)
}

private func statisticsScoreText(score: Double?) -> some View {
Expand Down
2 changes: 1 addition & 1 deletion Projects/Features/Sources/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public struct HomeView: View {
.padding(.bottom, 26)
}

if viewStore.isSolvedDailyTest == nil || needToShowProgressView {
if needToShowProgressView {
CustomProgressView()
}
}
Expand Down
22 changes: 22 additions & 0 deletions Projects/Network/Sources/DTO/TestStatisticsDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ public typealias StatisticsData = TestStatisticsDTO.StatisticsData
public typealias QuestionsStatisticsData = TestStatisticsDTO.QuestionsStatisticsData

extension StatisticsData: Equatable {}
public extension StatisticsData {
static func mockData(questionCount: Int) -> StatisticsData {
let questions = (1...questionCount).map { i -> QuestionsStatisticsData in
return QuestionsStatisticsData(
category: .init(color: "", iconUrl: "", name: ""),
keyword: "Keyword \(i)",
title: "Title \(i)",
avgScore: Double(i * 10 % 101),
questionId: i,
myScore: i * 5 % 101
)
}

let statisticsData = StatisticsData(
averageRate: Double(questionCount * 50 % 101),
questionsStatistics: questions,
solvedCount: questionCount
)

return statisticsData
}
}

extension QuestionsStatisticsData: Equatable, Hashable {
public static func == (lhs: TestStatisticsDTO.QuestionsStatisticsData, rhs: TestStatisticsDTO.QuestionsStatisticsData) -> Bool {
Expand Down

0 comments on commit 43c4ffc

Please sign in to comment.