Skip to content

Commit 3162ac6

Browse files
authored
feat: show verification record in CriteriaView (#7)
* design: edit BottomSheet background * design: bold text in CTAButton * feat: show verification record in CriteriaView
1 parent 768a4c4 commit 3162ac6

File tree

7 files changed

+70
-12
lines changed

7 files changed

+70
-12
lines changed

Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ target 'TuringMachine' do
1111
pod 'InjectHotReload'
1212
pod 'Alamofire'
1313
pod 'BottomSheetSwiftUI'
14+
pod 'WrappingHStack'
1415

1516
end

Podfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ PODS:
44
- InjectHotReload (1.2.2)
55
- SwiftFormat/CLI (0.51.13)
66
- SwiftLint (0.52.4)
7+
- WrappingHStack (2.2.10)
78

89
DEPENDENCIES:
910
- Alamofire
1011
- BottomSheetSwiftUI
1112
- InjectHotReload
1213
- SwiftFormat/CLI (~> 0.49)
1314
- SwiftLint
15+
- WrappingHStack
1416

1517
SPEC REPOS:
1618
trunk:
@@ -19,14 +21,16 @@ SPEC REPOS:
1921
- InjectHotReload
2022
- SwiftFormat
2123
- SwiftLint
24+
- WrappingHStack
2225

2326
SPEC CHECKSUMS:
2427
Alamofire: 0123a34370cb170936ae79a8df46cc62b2edeb88
2528
BottomSheetSwiftUI: 08b5ada340a164b7ef49cf04b6733a0bd3f02957
2629
InjectHotReload: e524b7c46ec063d84e407e65df5fe251cde19b32
2730
SwiftFormat: f4c21fdf8aacdd2db6ffe110f939e0548c9a7de3
2831
SwiftLint: 1cc5cd61ba9bacb2194e340aeb47a2a37fda00b3
32+
WrappingHStack: f784737f5707f8fea91b687074530dbefd2dbf05
2933

30-
PODFILE CHECKSUM: 1bf35b7564d090a5158e258670974a093d44d577
34+
PODFILE CHECKSUM: 2af91d01f9f1dd837544e47b464a3c7c9bb9ae54
3135

3236
COCOAPODS: 1.12.1

TuringMachine.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
CA3ED7E22A81732A0049FAD9 /* NumberBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA3ED7E12A81732A0049FAD9 /* NumberBadge.swift */; };
1011
CA5396912A800A670047BCDB /* RemoteImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA5396902A800A670047BCDB /* RemoteImage.swift */; };
1112
CA5396932A800A890047BCDB /* ImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA5396922A800A890047BCDB /* ImageCache.swift */; };
1213
CA5396952A8017E90047BCDB /* Int+Alphabet.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA5396942A8017E90047BCDB /* Int+Alphabet.swift */; };
@@ -53,6 +54,7 @@
5354
04CB4784166E4B9C3DCC71E4 /* Pods-TuringMachine.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TuringMachine.debug.xcconfig"; path = "Target Support Files/Pods-TuringMachine/Pods-TuringMachine.debug.xcconfig"; sourceTree = "<group>"; };
5455
9FB265AE9BDD7CEC2CC2F7E8 /* Pods-TuringMachine.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TuringMachine.release.xcconfig"; path = "Target Support Files/Pods-TuringMachine/Pods-TuringMachine.release.xcconfig"; sourceTree = "<group>"; };
5556
AB96405E94F89CE41C438FFB /* Pods_TuringMachine.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TuringMachine.framework; sourceTree = BUILT_PRODUCTS_DIR; };
57+
CA3ED7E12A81732A0049FAD9 /* NumberBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberBadge.swift; sourceTree = "<group>"; };
5658
CA5396902A800A670047BCDB /* RemoteImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteImage.swift; sourceTree = "<group>"; };
5759
CA5396922A800A890047BCDB /* ImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCache.swift; sourceTree = "<group>"; };
5860
CA5396942A8017E90047BCDB /* Int+Alphabet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+Alphabet.swift"; sourceTree = "<group>"; };
@@ -249,6 +251,7 @@
249251
CAF59A732A7B8E4900813B9C /* CTAButton.swift */,
250252
CAF59AA82A7EC13600813B9C /* ThreeDigitPicker.swift */,
251253
CA5396902A800A670047BCDB /* RemoteImage.swift */,
254+
CA3ED7E12A81732A0049FAD9 /* NumberBadge.swift */,
252255
);
253256
path = Shared;
254257
sourceTree = "<group>";
@@ -436,6 +439,7 @@
436439
CAF59AA32A7D4ECF00813B9C /* QuestionViewModel.swift in Sources */,
437440
CAF59A792A7B9DE400813B9C /* RegisterView.swift in Sources */,
438441
CAF59A8F2A7CD1D200813B9C /* GameViewModel.swift in Sources */,
442+
CA3ED7E22A81732A0049FAD9 /* NumberBadge.swift in Sources */,
439443
CAF59A8D2A7CD16900813B9C /* WebSocket.swift in Sources */,
440444
CAF59A7D2A7C0F4600813B9C /* NetworkManager.swift in Sources */,
441445
CAF59AA92A7EC13600813B9C /* ThreeDigitPicker.swift in Sources */,

TuringMachine/Views/Screens/CriteriaView.swift

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
11
import InjectHotReload
22
import SwiftUI
3+
import WrappingHStack
34

45
struct CriteriaView: View {
56
@ObservedObject private var inject = Inject.observer
67
@EnvironmentObject var viewModel: GameViewModel
8+
var recordForEachVerifier: [[Int]] {
9+
var computedRecord = Array(repeating: [Int](), count: 6)
10+
viewModel.verificationRecord.enumerated().forEach { stage, resultArray in
11+
let num = viewModel.proposalRecord[stage]
12+
resultArray.enumerated().forEach { verifierIndex, result in
13+
if result == .skip { return }
14+
computedRecord[verifierIndex].append(result == .correct ? num : -num)
15+
}
16+
}
17+
return computedRecord
18+
}
719

820
var body: some View {
921
List {
1022
if let problem = viewModel.problem {
1123
ForEach(Array(zip(problem.verifiers.indices, problem.verifiers)), id: \.0) { index, item in
12-
HStack {
13-
Image(systemName: "\(index.toAlphabet().lowercased()).square.fill")
14-
.foregroundColor(.blue)
15-
.font(.title3)
24+
VStack {
25+
HStack {
26+
Image(systemName: "\(index.toAlphabet().lowercased()).square.fill")
27+
.foregroundColor(.blue)
28+
.font(.title3)
1629

17-
Spacer(minLength: 20)
18-
RemoteImage(url: """
19-
https://turingmachine.info/images/criteriacards/\
20-
EN/TM_GameCards_EN-\(String(format: "%02d", item)).png
21-
""") {
22-
ProgressView()
30+
Spacer(minLength: 20)
31+
RemoteImage(url: """
32+
https://turingmachine.info/images/criteriacards/\
33+
EN/TM_GameCards_EN-\(String(format: "%02d", item)).png
34+
""") {
35+
ProgressView()
36+
}
37+
}
38+
}
39+
if recordForEachVerifier[index].count > 0 {
40+
WrappingHStack(recordForEachVerifier[index].indices, id: \.self) { recordIndex in
41+
NumberBadge(num: abs(recordForEachVerifier[index][recordIndex]),
42+
isCorrect: recordForEachVerifier[index][recordIndex] > 0)
2343
}
2444
}
2545
}
2646
} else {
2747
ProgressView()
2848
}
49+
Spacer()
50+
.listRowSeparator(.hidden, edges: .bottom)
51+
.listRowBackground(EmptyView())
2952
}
3053
.listStyle(.plain)
54+
.background(Color(.systemBackground))
3155
.enableInjection()
3256
}
3357
}

TuringMachine/Views/Screens/VerificationView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ struct VerificationView: View {
4646
}
4747
}
4848
}
49+
Spacer()
50+
.listRowSeparator(.hidden, edges: .bottom)
51+
.listRowBackground(EmptyView())
4952
}
5053
.listStyle(.plain)
5154
.enableInjection()

TuringMachine/Views/Shared/CTAButton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct CTAButton: View {
1616
.frame(maxWidth: .infinity)
1717
.controlSize(.regular)
1818
} else {
19-
Text(title)
19+
Text("**\(title)**")
2020
.frame(maxWidth: .infinity)
2121
}
2222
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import SwiftUI
2+
3+
struct NumberBadge: View {
4+
let num: Int
5+
let isCorrect: Bool
6+
7+
var body: some View {
8+
Text("\(num)")
9+
.font(.subheadline)
10+
.foregroundColor(.white)
11+
.padding(4)
12+
.background(RoundedRectangle(cornerRadius: 8).fill(isCorrect ? Color("Primary") : .red))
13+
.padding(.vertical, 3)
14+
}
15+
}
16+
17+
struct NumberBadge_Previews: PreviewProvider {
18+
static var previews: some View {
19+
NumberBadge(num: 342, isCorrect: true)
20+
NumberBadge(num: 342, isCorrect: false)
21+
}
22+
}

0 commit comments

Comments
 (0)