From 07a0b334d59e078b8bfb4ae8b58a4aa4d0e2c3a3 Mon Sep 17 00:00:00 2001 From: Tarlan Ismayilsoy Date: Thu, 26 Oct 2023 21:32:28 +0400 Subject: [PATCH] Add badge to feedback cell --- .../CorrectionSidebar/FeedbackCellView.swift | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/Themis/Views/Assessment/CorrectionSidebar/FeedbackCellView.swift b/Themis/Views/Assessment/CorrectionSidebar/FeedbackCellView.swift index 3d8ba54b..8428f0a6 100644 --- a/Themis/Views/Assessment/CorrectionSidebar/FeedbackCellView.swift +++ b/Themis/Views/Assessment/CorrectionSidebar/FeedbackCellView.swift @@ -37,10 +37,9 @@ struct FeedbackCellView: View { let gradingCriteria: [GradingCriterion] var body: some View { - VStack(alignment: .leading, spacing: 5) { + VStack(alignment: .leading, spacing: 10) { HStack { - Text(feedbackText) - .foregroundColor(.getTextColor(forCredits: feedback.baseFeedback.credits ?? 0.0)) + feedbackTextLabel Spacer() @@ -90,6 +89,17 @@ struct FeedbackCellView: View { .scaleEffect(isTapped ? 1.05 : 1.0) } + @ViewBuilder + private var feedbackTextLabel: some View { + if feedback.isSuggested { + suggestionBadge + } else { + Text(feedbackText) + .foregroundColor(.getTextColor(forCredits: feedback.baseFeedback.credits ?? 0.0)) + } + } + + @ViewBuilder private var pointLabel: some View { Text(String(format: "%.1f", feedback.baseFeedback.credits ?? 0.0) + "P") .font(.headline) @@ -99,6 +109,7 @@ struct FeedbackCellView: View { .cornerRadius(5) } + @ViewBuilder private var editButton: some View { Button { showEditFeedback = true @@ -112,4 +123,37 @@ struct FeedbackCellView: View { .disabled(editingDisabled) .isHidden(feedback.baseFeedback.type?.isAutomatic ?? false) } + + @ViewBuilder + private var suggestionBadge: some View { + HStack(spacing: 4) { + Image("SuggestedFeedbackSymbol") + .renderingMode(.template) + .resizable() + .scaledToFit() + .frame(width: 15, height: 15) + + Text("SUGGESTED") + .font(.footnote) + .fontWeight(.bold) + } + .frame(height: 18) + .padding(8) + .foregroundStyle(.white) + .background(Color.feedbackSuggestionColor) + .cornerRadius(5) + } +} + +struct FeedbackCellView_Previews: PreviewProvider { + static var assessmentVM = AssessmentViewModel(exercise: .mockText, readOnly: false) + static var assessmentResult = TextAssessmentResult() + + static var previews: some View { + FeedbackCellView(assessmentVM: assessmentVM, + assessmentResult: assessmentResult, + feedback: AssessmentFeedback(scope: .inline), + gradingCriteria: []) + .padding(.horizontal, 200) + } }