From 43c4ffc75e82f70abdb1a9e046d97365c8a7770e Mon Sep 17 00:00:00 2001 From: YoungBin Lee Date: Sat, 30 Sep 2023 15:19:12 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=99=88=20=EB=B7=B0=20=EB=A1=9C?= =?UTF-8?q?=EB=94=A9=20=EC=9E=90=EC=97=B0=EC=8A=A4=EB=9F=BD=EA=B2=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyTestList/DailyTestListFeature.swift | 2 ++ .../DailyTestList/DailyTestListView.swift | 16 +++++++++----- Projects/Features/Sources/Home/HomeView.swift | 2 +- .../Sources/DTO/TestStatisticsDTO.swift | 22 +++++++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Projects/Features/Sources/Home/DailyTestList/DailyTestListFeature.swift b/Projects/Features/Sources/Home/DailyTestList/DailyTestListFeature.swift index b4140462..1c82f761 100644 --- a/Projects/Features/Sources/Home/DailyTestList/DailyTestListFeature.swift +++ b/Projects/Features/Sources/Home/DailyTestList/DailyTestListFeature.swift @@ -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 diff --git a/Projects/Features/Sources/Home/DailyTestList/DailyTestListView.swift b/Projects/Features/Sources/Home/DailyTestList/DailyTestListView.swift index 12cbacea..6809d370 100644 --- a/Projects/Features/Sources/Home/DailyTestList/DailyTestListView.swift +++ b/Projects/Features/Sources/Home/DailyTestList/DailyTestListView.swift @@ -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) } } @@ -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 { diff --git a/Projects/Features/Sources/Home/HomeView.swift b/Projects/Features/Sources/Home/HomeView.swift index c8267b4b..994d9fa7 100644 --- a/Projects/Features/Sources/Home/HomeView.swift +++ b/Projects/Features/Sources/Home/HomeView.swift @@ -80,7 +80,7 @@ public struct HomeView: View { .padding(.bottom, 26) } - if viewStore.isSolvedDailyTest == nil || needToShowProgressView { + if needToShowProgressView { CustomProgressView() } } diff --git a/Projects/Network/Sources/DTO/TestStatisticsDTO.swift b/Projects/Network/Sources/DTO/TestStatisticsDTO.swift index c320f0fc..1b7c4e6d 100644 --- a/Projects/Network/Sources/DTO/TestStatisticsDTO.swift +++ b/Projects/Network/Sources/DTO/TestStatisticsDTO.swift @@ -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 {