Skip to content

Commit

Permalink
feat: Alert for outdated course calendars on the course home screen
Browse files Browse the repository at this point in the history
shafqat-muneer authored May 7, 2024
1 parent 4706755 commit bd9f081
Showing 7 changed files with 64 additions and 9 deletions.
1 change: 1 addition & 0 deletions Core/Core/Extensions/Notification.swift
Original file line number Diff line number Diff line change
@@ -17,4 +17,5 @@ public extension Notification.Name {
static let onBlockCompletion = Notification.Name.init("onBlockCompletion")
static let shiftCourseDates = Notification.Name("shiftCourseDates")
static let profileUpdated = Notification.Name("profileUpdated")
static let getCourseDates = Notification.Name("getCourseDates")
}
41 changes: 39 additions & 2 deletions Course/Course/Presentation/Container/CourseContainerView.swift
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ public struct CourseContainerView: View {

@ObservedObject
public var viewModel: CourseContainerViewModel
@ObservedObject
public var courseDatesViewModel: CourseDatesViewModel
@State private var isAnimatingForTap: Bool = false
public var courseID: String
private var title: String
@@ -39,6 +41,7 @@ public struct CourseContainerView: View {

public init(
viewModel: CourseContainerViewModel,
courseDatesViewModel: CourseDatesViewModel,
courseID: String,
title: String
) {
@@ -55,6 +58,7 @@ public struct CourseContainerView: View {
}
self.courseID = courseID
self.title = title
self.courseDatesViewModel = courseDatesViewModel
}

public var body: some View {
@@ -112,8 +116,32 @@ public struct CourseContainerView: View {
}
}
}

switch courseDatesViewModel.eventState {
case .removedCalendar:
showDatesSuccessView(
title: CourseLocalization.CourseDates.calendarEvents,
message: CourseLocalization.CourseDates.calendarEventsRemoved
)
case .updatedCalendar:
showDatesSuccessView(
title: CourseLocalization.CourseDates.calendarEvents,
message: CourseLocalization.CourseDates.calendarEventsUpdated
)
default:
EmptyView()
}
}

private func showDatesSuccessView(title: String, message: String) -> some View {
return DatesSuccessView(
title: title,
message: message
) {
courseDatesViewModel.resetEventState()
}
}

private func backButton(containerWidth: CGFloat) -> some View {
ZStack(alignment: .topLeading) {
if !collapsed {
@@ -184,8 +212,7 @@ public struct CourseContainerView: View {
courseID: courseID,
coordinate: $coordinate,
collapsed: $collapsed,
viewModel: Container.shared.resolve(CourseDatesViewModel.self,
arguments: courseID, title)!
viewModel: courseDatesViewModel
)
.tabItem {
tab.image
@@ -313,6 +340,16 @@ struct CourseScreensView_Previews: PreviewProvider {
enrollmentEnd: nil,
coreAnalytics: CoreAnalyticsMock()
),
courseDatesViewModel: CourseDatesViewModel(
interactor: CourseInteractor.mock,
router: CourseRouterMock(),
cssInjector: CSSInjectorMock(),
connectivity: Connectivity(),
config: ConfigMock(),
courseID: "1",
courseName: "a",
analytics: CourseAnalyticsMock()
),
courseID: "", title: "Title of Course")
}
}
Original file line number Diff line number Diff line change
@@ -140,6 +140,7 @@ public class CourseContainerViewModel: BaseCourseViewModel {
do {
if isInternetAvaliable {
courseStructure = try await interactor.getCourseBlocks(courseID: courseID)
NotificationCenter.default.post(name: .getCourseDates, object: courseID)
isShowProgress = false
isShowRefresh = false
if let courseStructure {
3 changes: 1 addition & 2 deletions Course/Course/Presentation/Dates/CourseDatesView.swift
Original file line number Diff line number Diff line change
@@ -114,8 +114,7 @@ public struct CourseDatesView: View {
} else {
return DatesSuccessView(
title: title,
message: message,
selectedTab: .dates
message: message
) {
viewModel.resetEventState()
}
12 changes: 12 additions & 0 deletions Course/Course/Presentation/Dates/CourseDatesViewModel.swift
Original file line number Diff line number Diff line change
@@ -195,6 +195,18 @@ extension CourseDatesViewModel {
selector: #selector(handleShiftDueDates),
name: .shiftCourseDates, object: nil
)

NotificationCenter.default.addObserver(
self,
selector: #selector(getCourseDates),
name: .getCourseDates, object: nil
)
}

@objc private func getCourseDates(_ notification: Notification) {
Task {
await getCourseDates(courseID: courseID)
}
}

@objc private func handleShiftDueDates(_ notification: Notification) {
7 changes: 2 additions & 5 deletions Course/Course/Views/DatesSuccessView.swift
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public struct DatesSuccessView: View {

private var title: String
private var message: String
var selectedTab: Tab
var selectedTab: Tab?
var courseDatesViewModel: CourseDatesViewModel?
var courseContainerViewModel: CourseContainerViewModel?
var action: () -> Void = {}
@@ -29,12 +29,10 @@ public struct DatesSuccessView: View {
init (
title: String,
message: String,
selectedTab: Tab,
dismissAction: @escaping () -> Void
) {
self.title = title
self.message = message
self.selectedTab = selectedTab
self.dismissAction = dismissAction
}

@@ -149,8 +147,7 @@ struct DatesSuccessView_Previews: PreviewProvider {
static var previews: some View {
DatesSuccessView(
title: CourseLocalization.CourseDates.toastSuccessTitle,
message: CourseLocalization.CourseDates.toastSuccessMessage,
selectedTab: .course
message: CourseLocalization.CourseDates.toastSuccessMessage
) {}
}
}
8 changes: 8 additions & 0 deletions OpenEdX/Router.swift
Original file line number Diff line number Diff line change
@@ -395,8 +395,16 @@ public class Router: AuthorizationRouter,
enrollmentStart,
enrollmentEnd
)!

let datesVm = Container.shared.resolve(
CourseDatesViewModel.self,
arguments: courseID,
title
)!

let screensView = CourseContainerView(
viewModel: vm,
courseDatesViewModel: datesVm,
courseID: courseID,
title: title
)

0 comments on commit bd9f081

Please sign in to comment.