Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions Paxo/Storage/HistoryBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ enum HistoryBrowser {
}
}

/// 주의 시작 요일은 기기의 달력을 따른다.
static func summary(_ items: [SolveResult], now: Date = Date(), calendar: Calendar = .current) -> HistorySummary {
let shown = visible(items)
let week = calendar.dateInterval(of: .weekOfYear, for: now)
return HistorySummary(
solvedThisWeek: shown.filter { week?.contains($0.date) == true }.count,
incorrect: shown.filter { $0.correctness == .incorrect }.count,
recovered: shown.filter { $0.correctness == .incorrect && $0.lastReviewCorrectness == .correct }.count,
pendingReview: shown.filter(\.needsReview).count
)
}

static func days(_ items: [SolveResult], calendar: Calendar = .current) -> [HistoryDay] {
Dictionary(grouping: items) { calendar.startOfDay(for: $0.date) }
.map { HistoryDay(date: $0.key, items: $0.value.sorted { $0.date > $1.date }) }
Expand Down Expand Up @@ -71,4 +83,12 @@ struct HistorySubjectGroup: Identifiable {
let name: String
let items: [SolveResult]
var id: String { subjectID?.uuidString ?? "unclassified" }
var incorrectCount: Int { items.filter { $0.correctness == .incorrect }.count }
}

struct HistorySummary: Equatable {
let solvedThisWeek: Int
let incorrect: Int
let recovered: Int
let pendingReview: Int
}
26 changes: 20 additions & 6 deletions Paxo/UI/HistoryArchiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ struct HistoryArchiveView: View {
}
}

/// 날짜·과목·검색으로 좁힌 상태에서는 지금 보이는 목록의 오답만 다시 푼다.
private var scopedReviewQueue: [SolveResult] {
HistoryBrowser.reviewQueue(matchingItems)
}

var body: some View {
Group {
if showsReview {
ReviewSessionView(queue: appState.reviewQueue, onClose: { showsReview = false })
.padding(20)
ReviewSessionView(
queue: scopedReviewQueue,
subjectName: { appState.subject(for: $0)?.name },
onClose: { showsReview = false }
)
.padding(20)
} else if showsDetail {
ResultView(onBack: { showsDetail = false }, backTitle: "풀이 기록으로", isHistory: true)
} else {
Expand All @@ -55,6 +64,11 @@ struct HistoryArchiveView: View {
}
)
}
if selectedDate == nil, selectedSubjectKey == nil, query.isEmpty,
!appState.visibleHistory.isEmpty
{
HistorySummaryView(summary: HistoryBrowser.summary(appState.visibleHistory))
}
HistoryStorageNotice()
searchField
groupingControls
Expand Down Expand Up @@ -135,9 +149,9 @@ struct HistoryArchiveView: View {
.monospacedDigit()
}
HStack {
Button("오답 다시 풀기 (\(appState.reviewQueue.count))") { showsReview = true }
.disabled(appState.isSolving || appState.reviewQueue.isEmpty)
.help("오답으로 표시한 문제를 정답과 해설을 가린 채 다시 풉니다.")
Button("오답 다시 풀기 (\(scopedReviewQueue.count))") { showsReview = true }
.disabled(appState.isSolving || scopedReviewQueue.isEmpty)
.help("지금 보이는 목록에서 오답으로 표시한 문제를 정답과 해설을 가린 채 다시 풉니다.")
Spacer()
Button("모든 기록 삭제…", role: .destructive) { showsDeleteConfirmation = true }
.disabled(appState.isSolving)
Expand Down Expand Up @@ -231,7 +245,7 @@ struct HistoryArchiveView: View {
.frame(width: 36)
VStack(alignment: .leading, spacing: 5) {
Text(group.name).font(.callout.weight(.semibold))
Text("풀이 \(group.items.count)개")
Text("풀이 \(group.items.count)개 · 오답 \(group.incorrectCount)개")
.font(.caption)
.foregroundStyle(.secondary)
}
Expand Down
33 changes: 33 additions & 0 deletions Paxo/UI/HistorySummaryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SwiftUI

/// 기록을 열자마자 복습할 양이 보이도록 숫자만 한 줄로 요약한다.
struct HistorySummaryView: View {
let summary: HistorySummary

var body: some View {
HStack(spacing: 8) {
tile("이번 주 풀이", summary.solvedThisWeek)
tile("오답", summary.incorrect)
tile("다시 맞힘", summary.recovered)
tile("복습 남음", summary.pendingReview, isEmphasized: summary.pendingReview > 0)
}
.accessibilityElement(children: .combine)
}

private func tile(_ title: String, _ value: Int, isEmphasized: Bool = false) -> some View {
VStack(alignment: .leading, spacing: 2) {
Text("\(value)")
.font(.title3.weight(.semibold))
.monospacedDigit()
.foregroundStyle(isEmphasized ? PaxoStyle.brand : .primary)
Text(title)
.font(.caption2)
.foregroundStyle(.secondary)
.lineLimit(1)
}
.padding(.horizontal, 10)
.padding(.vertical, 8)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.primary.opacity(0.045), in: RoundedRectangle(cornerRadius: 8))
}
}
5 changes: 5 additions & 0 deletions Paxo/UI/MenuContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ struct MenuContentView: View {
.font(.caption2)
.foregroundStyle(.secondary)
}
if !appState.reviewQueue.isEmpty {
Text("다시 풀 오답 \(appState.reviewQueue.count)개는 설정의 풀이 기록 탭에서 풀 수 있습니다.")
.font(.caption2)
.foregroundStyle(.secondary)
}
}
}
Divider()
Expand Down
28 changes: 26 additions & 2 deletions Paxo/UI/ReviewSessionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import SwiftUI
/// 시작할 때의 오답 목록을 고정해, 채점할 때마다 순서가 바뀌어 문제를 건너뛰지 않게 한다.
struct ReviewSessionView: View {
@EnvironmentObject private var appState: AppState
let subjectName: (UUID) -> String?
let onClose: () -> Void
@State private var queue: [SolveResult]
@State private var index = 0
@State private var isRevealed = false
@State private var recoveredCount = 0
@State private var skippedCount = 0

/// 첫 화면부터 문제가 보이도록 목록을 생성 시점에 받는다.
init(queue: [SolveResult], onClose: @escaping () -> Void) {
init(
queue: [SolveResult], subjectName: @escaping (UUID) -> String? = { _ in nil },
onClose: @escaping () -> Void
) {
self.subjectName = subjectName
self.onClose = onClose
_queue = State(initialValue: queue)
}
Expand Down Expand Up @@ -50,6 +56,14 @@ struct ReviewSessionView: View {
VStack(alignment: .leading, spacing: 12) {
ScrollView {
VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 6) {
Text(subjectName(item.id) ?? "미분류")
Text("·")
Text(item.date, format: .dateTime.month().day())
Text("에 틀린 문제")
}
.font(.caption)
.foregroundStyle(.secondary)
problemImage(item)
if isRevealed {
answer(item)
Expand Down Expand Up @@ -79,6 +93,8 @@ struct ReviewSessionView: View {
.foregroundStyle(.secondary)
}
Spacer()
Button("건너뛰기") { skip() }
.help("기록을 남기지 않고 다음 문제로 넘어갑니다.")
Button("정답 보기") { isRevealed = true }
.buttonStyle(.borderedProminent)
.keyboardShortcut(.defaultAction)
Expand Down Expand Up @@ -128,7 +144,9 @@ struct ReviewSessionView: View {
Text(
queue.isEmpty
? "기록에서 오답으로 표시한 문제가 여기에 모입니다."
: "또 틀린 문제는 다음 다시 풀기에 남아 있습니다."
: skippedCount > 0
? "건너뛴 \(skippedCount)문제와 또 틀린 문제는 다음 다시 풀기에 남아 있습니다."
: "또 틀린 문제는 다음 다시 풀기에 남아 있습니다."
)
.font(.caption)
.foregroundStyle(.secondary)
Expand All @@ -146,4 +164,10 @@ struct ReviewSessionView: View {
isRevealed = false
index += 1
}

private func skip() {
skippedCount += 1
isRevealed = false
index += 1
}
}
31 changes: 31 additions & 0 deletions PaxoTests/ReviewQueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@ struct ReviewQueueTests {
#expect(queue.map(\.id) == [oldWrong.id, newWrong.id, reviewedLongAgo.id, reviewedRecently.id])
}

@Test func summaryCountsThisWeekAndReviewProgress() throws {
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = try #require(TimeZone(identifier: "Asia/Seoul"))
calendar.firstWeekday = 2
// 2026-11-11은 수요일이라 같은 주는 11-09(월)부터다.
let now = try #require(calendar.date(from: DateComponents(year: 2026, month: 11, day: 11, hour: 12)))
let monday = try #require(calendar.date(from: DateComponents(year: 2026, month: 11, day: 9, hour: 0)))
let lastSunday = monday.addingTimeInterval(-1)

let thisWeekCorrect = result(.correct, solvedAt: now.timeIntervalSince1970)
let thisWeekWrong = result(.incorrect, solvedAt: monday.timeIntervalSince1970)
var lastWeekRecovered = result(.incorrect, solvedAt: lastSunday.timeIntervalSince1970)
lastWeekRecovered.recordReview(.correct, at: now)
let lastWeekUngraded = result(nil, solvedAt: lastSunday.timeIntervalSince1970 - 100)

let summary = HistoryBrowser.summary(
[thisWeekCorrect, thisWeekWrong, lastWeekRecovered, lastWeekUngraded], now: now, calendar: calendar
)
#expect(summary == HistorySummary(solvedThisWeek: 2, incorrect: 2, recovered: 1, pendingReview: 1))
}

@Test func narrowedListReviewsOnlyItsOwnWrongAnswers() {
let inScope = result(.incorrect, solvedAt: 10)
let outOfScope = result(.incorrect, solvedAt: 20)
let group = HistorySubjectGroup(subjectID: UUID(), name: "수학", items: [inScope, result(.correct, solvedAt: 5)])

#expect(HistoryBrowser.reviewQueue(group.items).map(\.id) == [inScope.id])
#expect(HistoryBrowser.reviewQueue([inScope, outOfScope]).count == 2)
#expect(group.incorrectCount == 1)
}

/// 복습 필드가 없던 버전의 기록이 그대로 열려야 기존 사용자의 기록이 사라지지 않는다.
@Test func recordsSavedBeforeReviewFieldsStillDecode() throws {
let legacy = """
Expand Down
Loading