Skip to content

Commit

Permalink
chore: course dates feature (#149)
Browse files Browse the repository at this point in the history
* chore: update view top margin, handle case for today dat with the blocks, refactoring

* chore: address feedback, disable block if content is verified only

* refactor: remove unused import
  • Loading branch information
mumer92 authored Nov 8, 2023
1 parent 1f51cfe commit 7256a71
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 135 deletions.
28 changes: 14 additions & 14 deletions Course/Course/Data/CourseRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ And there are various ways of describing it-- call it oral poetry or
},
{
"assignment_type": "Problem Set",
"complete": false,
"complete": true,
"date": "2023-09-14T23:30:00Z",
"date_type": "assignment-due-date",
"description": "",
Expand All @@ -1096,19 +1096,19 @@ And there are various ways of describing it-- call it oral poetry or
"extra_info": null,
"first_component_block_id": "block-v1:MITx+6.00.1x+2T2023a+type@problem+block@bd89c1dd129240f99bb8c5cbe3f56530"
},
{
"assignment_type": "Problem Set",
"complete": false,
"date": "2023-09-14T23:30:00Z",
"date_type": "assignment-due-date",
"description": "",
"learner_has_access": true,
"link": "https://courses.edx.org/courses/course-v1:MITx+6.00.1x+2T2023a/jump_to/block-v1:MITx+6.00.1x+2T2023a+type@sequential+block@ca19e125470846f2a36ad1225410e39aa",
"link_text": "",
"title": "Problem Set 1.1",
"extra_info": null,
"first_component_block_id": "block-v1:MITx+6.00.1x+2T2023a+type@problem+block@bd89c1dd129240f99bb8c5cbe3f56530a"
},
{
"assignment_type": "Problem Set",
"complete": false,
"date": "2023-09-14T23:30:00Z",
"date_type": "assignment-due-date",
"description": "",
"learner_has_access": true,
"link": "",
"link_text": "",
"title": "Problem Set 1.1",
"extra_info": null,
"first_component_block_id": "block-v1:MITx+6.00.1x+2T2023a+type@problem+block@bd89c1dd129240f99bb8c5cbe3f56530a"
},
{
"assignment_type": "Problem Set",
"complete": false,
Expand Down
45 changes: 19 additions & 26 deletions Course/Course/Domain/Model/CourseDates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ public struct CourseDates {
var hasToday = false
let today = Date.today

let calendar = Calendar.current
let todayComponents = calendar.dateComponents([.year, .month, .day], from: .today)

for block in courseDateBlocks {
let date = block.date
if date == today {
let dateComponents = calendar.dateComponents([.year, .month, .day], from: date)

if dateComponents == todayComponents {
hasToday = true
}

Expand Down Expand Up @@ -66,15 +71,20 @@ extension Date {
}

var isToday: Bool {
return Date.compare(self, to: .today) == .orderedSame
let calendar = Calendar.current
let selfComponents = calendar.dateComponents([.year, .month, .day], from: self)
let todayComponents = calendar.dateComponents([.year, .month, .day], from: .today)
return selfComponents == todayComponents
}

var isInFuture: Bool {
return Date.compare(self, to: .today) == .orderedDescending
}
}

public struct CourseDateBlock {
public struct CourseDateBlock: Identifiable {
public let id: UUID = UUID()

let assignmentType: String?
let complete: Bool?
let date: Date
Expand All @@ -86,12 +96,8 @@ public struct CourseDateBlock {
let extraInfo: String?
let firstComponentBlockID: String

var blockTitle: String {
if isToday {
return CoreLocalization.CourseDates.today
} else {
return blockStatus.title
}
var formattedDate: String {
return date.dateToString(style: .shortWeekdayMonthDayYear)
}

var isInPast: Bool {
Expand Down Expand Up @@ -138,6 +144,10 @@ public struct CourseDateBlock {
return !isUnreleased && isLearnerAssignment
}

var isAvailable: Bool {
return learnerHasAccess && (!isUnreleased || !isLearnerAssignment)
}

var blockStatus: BlockStatus {
if isComplete {
return .completed
Expand Down Expand Up @@ -191,21 +201,4 @@ public enum BlockStatus {
default: return .event
}
}

var title: String {
switch self {
case .completed:
return CoreLocalization.CourseDates.completed
case .pastDue:
return CoreLocalization.CourseDates.pastDue
case .dueNext:
return CoreLocalization.CourseDates.dueNext
case .unreleased:
return CoreLocalization.CourseDates.unreleased
case .verifiedOnly:
return CoreLocalization.CourseDates.verifiedOnly
default:
return ""
}
}
}
Loading

0 comments on commit 7256a71

Please sign in to comment.