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 1 commit
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
41 changes: 31 additions & 10 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,9 +216,32 @@ 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] {
if let _ = viewModel.sequentialsDownloadState[sequential.id] {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we refactor it something like this:

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

Then we can avoid following two warnings:

Unused Optional Binding Violation: Prefer `!= nil` over `let _ =` (unused_optional_binding)

Prefer For-Where Violation: `where` clauses are preferred over a single `if` inside a `for` (for_where)

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