Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: hide grades when sub section dependents not available #99

Merged
merged 2 commits into from
Nov 29, 2024
Merged
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
46 changes: 33 additions & 13 deletions Course/Course/Presentation/Subviews/CustomDisclosureGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ struct CustomDisclosureGroup: View {
VStack(alignment: .leading) {
HStack {
if sequential.completion == 1 {
CoreAssets.finishedSequence.swiftUIImage.renderingMode(.template)
CoreAssets.finishedSequence.swiftUIImage
.renderingMode(.template)
.resizable()
.foregroundColor(Theme.Colors.success)
.frame(width: 20, height: 20)
Expand All @@ -145,13 +146,10 @@ struct CustomDisclosureGroup: View {
alignment: .leading
)
}
if let sequentialProgress = sequential.sequentialProgress,
let assignmentType = sequentialProgress.assignmentType,
let numPointsEarned = sequentialProgress.numPointsEarned,
let numPointsPossible = sequentialProgress.numPointsPossible,
let due = sequential.due {
let daysRemaining = getAssignmentStatus(for: due)
Text("\(assignmentType) - \(daysRemaining) - \(numPointsEarned) / \(numPointsPossible)")
if let assignmentStatusText = assignmentStatusText(
sequential: sequential
) {
Text(assignmentStatusText)
.font(Theme.Fonts.bodySmall)
.multilineTextAlignment(.leading)
.lineLimit(2)
Expand Down Expand Up @@ -218,12 +216,34 @@ struct CustomDisclosureGroup: View {
}
}

private func assignmentStatusText(
sequential: CourseSequential
) -> String? {

guard let sequentialProgress = sequential.sequentialProgress,
let assignmentType = sequentialProgress.assignmentType,
let numPointsEarned = sequentialProgress.numPointsEarned,
let numPointsPossible = sequentialProgress.numPointsPossible,
let due = sequential.due else {
return nil
}

let daysRemaining = getAssignmentStatus(for: due)

if let courseVertical = sequential.childs.first,
courseVertical.childs.isEmpty {
return "\(assignmentType) - \(daysRemaining)"
}

return "\(assignmentType) - \(daysRemaining) - \(numPointsEarned) / \(numPointsPossible)"

}

private func canDownloadAllSections(in chapter: CourseChapter) -> Bool {
for sequential in chapter.childs {
if let state = viewModel.sequentialsDownloadState[sequential.id] {
return true
}
for sequential in chapter.childs where viewModel.sequentialsDownloadState[sequential.id] != nil {
return true
}

return false
}

Expand Down Expand Up @@ -383,7 +403,7 @@ struct CustomDisclosureGroup_Previews: PreviewProvider {
courseStart: Date(),
courseEnd: nil,
enrollmentStart: Date(),
enrollmentEnd: nil,
enrollmentEnd: nil,
lastVisitedBlockID: nil,
coreAnalytics: CoreAnalyticsMock(),
serverConfig: ServerConfigProtocolMock()
Expand Down
Loading