Skip to content

Commit

Permalink
chore: hide grades when sub section dependents not available (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedbashir authored Nov 29, 2024
1 parent d2fc507 commit e9c4928
Showing 1 changed file with 33 additions and 13 deletions.
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

0 comments on commit e9c4928

Please sign in to comment.