-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuizRowView.swift
120 lines (101 loc) · 4.32 KB
/
QuizRowView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// QuizRowView.swift
// MathQuiz
//
// Created by Susnata Basak on 10/13/24.
//
import SwiftUI
struct QuizRowView: View {
@EnvironmentObject var theme: Theme
let quiz: Quiz
var body: some View {
VStack {
HStack {
VStack(alignment: .leading, spacing: 6) {
Text(quiz.getCreatedAtDate())
.font(theme.fonts.small)
.foregroundColor(theme.colors.text)
HStack(alignment: .bottom) {
Text("\(quiz.status.rawValue)")
.font(.subheadline)
.fontWeight(.bold)
.foregroundColor(theme.colors.text)
}
}
VStack(alignment: .leading, spacing: 6) {
Text("Difficulty")
.font(theme.fonts.small)
.foregroundColor(theme.colors.text)
Text("\(quiz.difficultyLevel.rawValue)")
.font(.subheadline)
.fontWeight(.bold)
.foregroundColor(theme.colors.text)
}.padding(.horizontal)
Spacer()
VStack(alignment: .trailing, spacing: 6) {
Image(systemName: quiz.getPercentageScore >= 80 ? "hand.thumbsup.fill": "hand.thumbsdown.fill")
.foregroundColor(quiz.getPercentageScore >= 80 ? theme.colors.success : theme.colors.error)
HStack(alignment: .bottom) {
Text("score")
.font(theme.fonts.small)
.font(.subheadline)
.foregroundColor(theme.colors.text)
Text("\(quiz.getPercentageScore)%")
.font(.subheadline)
.fontWeight(.bold)
.foregroundColor(theme.colors.text)
}
}
}
.padding(4)
}
.cornerRadius(8)
.padding(.vertical, 4)
}
private var scoreColor: Color {
let score = quiz.getPercentageScore
if score >= 80 {
return theme.colors.success
} else if score >= 60 {
return theme.colors.error
} else {
return theme.colors.error
}
}
}
struct QuizRowView_Previews: PreviewProvider {
static var previews: some View {
Group {
// High score quiz
QuizRowView(quiz: mockQuiz(score: 90, status: .completed))
.environmentObject(Theme.theme5)
.previewDisplayName("High Score")
// Medium score quiz
QuizRowView(quiz: mockQuiz(score: 70, status: .completed))
.environmentObject(Theme.theme1)
.previewDisplayName("Medium Score")
// Low score quiz
QuizRowView(quiz: mockQuiz(score: 40, status: .completed))
.environmentObject(Theme.theme1)
.previewDisplayName("Low Score")
// In-progress quiz
QuizRowView(quiz: mockQuiz(score: 0, status: .inProgress))
.environmentObject(Theme.theme1)
.previewDisplayName("In Progress")
// Dark mode
QuizRowView(quiz: mockQuiz(score: 80, status: .completed))
.environmentObject(Theme.theme1)
.preferredColorScheme(.dark)
.previewDisplayName("Dark Mode")
}
.padding()
.previewLayout(.sizeThatFits)
}
static func mockQuiz(score: Int, status: CompletionStatus) -> Quiz {
let quiz = Quiz(operation: .add, difficultyLevel: .easy, totalProblems: 10)
quiz.status = status
quiz.score = Score(totalCorrect: score, totalIncorrect: 10 - score)
quiz.createdAt = Date()
return quiz
}
}