Skip to content

Commit

Permalink
fix: change EnrollmentsStatus value isActive to recentlyActive (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanStepanok authored Oct 29, 2024
1 parent d7ad72a commit 8cfe33f
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 41 deletions.
1 change: 1 addition & 0 deletions Core/Core/Configuration/Connectivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Alamofire
import Combine
import Foundation

public enum InternetState {
case reachable
Expand Down
8 changes: 4 additions & 4 deletions Core/Core/Data/Model/Data_EnrollmentsStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ extension DataLayer {
public struct EnrollmentsStatusElement: Codable {
public let courseID: String?
public let courseName: String?
public let isActive: Bool?
public let recentlyActive: Bool?

public enum CodingKeys: String, CodingKey {
case courseID = "course_id"
case courseName = "course_name"
case isActive = "is_active"
case recentlyActive = "recently_active"
}

public init(courseID: String?, courseName: String?, isActive: Bool?) {
public init(courseID: String?, courseName: String?, recentlyActive: Bool?) {
self.courseID = courseID
self.courseName = courseName
self.isActive = isActive
self.recentlyActive = recentlyActive
}
}

Expand Down
10 changes: 5 additions & 5 deletions Core/Core/Domain/Model/CourseForSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public struct CourseForSync: Identifiable {
public let courseID: String
public let name: String
public var synced: Bool
public var active: Bool
public var recentlyActive: Bool

public init(id: UUID = UUID(), courseID: String, name: String, synced: Bool, active: Bool) {
public init(id: UUID = UUID(), courseID: String, name: String, synced: Bool, recentlyActive: Bool) {
self.id = id
self.courseID = courseID
self.name = name
self.synced = synced
self.active = active
self.recentlyActive = recentlyActive
}
}

Expand All @@ -29,13 +29,13 @@ extension DataLayer.EnrollmentsStatus {
self.compactMap {
guard let courseID = $0.courseID,
let courseName = $0.courseName,
let isActive = $0.isActive else { return nil }
let recentlyActive = $0.recentlyActive else { return nil }
return CourseForSync(
id: UUID(),
courseID: courseID,
name: courseName,
synced: false,
active: isActive
recentlyActive: recentlyActive
)
}
}
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Extensions/Container+App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import Swinject
import UIKit

public extension Container {
static var shared: Container = {
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Network/Alamofire+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Alamofire
import Foundation

public extension Error {
var isUpdateRequeiredError: Bool {
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Network/NetworkLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Alamofire
import Foundation

public class NetworkLogger: EventMonitor {

Expand Down
2 changes: 1 addition & 1 deletion OpenEdX/View/MainScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extension MainScreenViewModel {
}

do {
var coursesForSync = try await profileInteractor.enrollmentsStatus().filter { $0.active }
var coursesForSync = try await profileInteractor.enrollmentsStatus().filter { $0.recentlyActive }

let selectedCourses = await calendarManager.filterCoursesBySelected(fetchedCourses: coursesForSync)

Expand Down
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ abstract_target "App" do
project './Core/Core.xcodeproj'
workspace './Core/Core.xcodeproj'
#Networking
pod 'Alamofire', '~> 5.9'
#Keychain
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '5.10.0'
#Keychain
pod 'KeychainSwift', '~> 24.0'
#SwiftUI backward UIKit access
#pod 'Introspect', '~> 0.6'
Expand Down
15 changes: 10 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Alamofire (5.9.1)
- Alamofire (5.10.0)
- KeychainSwift (24.0.0)
- Kingfisher (8.0.3)
- Sourcery (1.8.0):
Expand All @@ -13,7 +13,7 @@ PODS:
- Swinject (2.9.1)

DEPENDENCIES:
- Alamofire (~> 5.9)
- Alamofire (from `https://github.com/Alamofire/Alamofire.git`, tag `5.10.0`)
- KeychainSwift (~> 24.0)
- Kingfisher (~> 8.0)
- SwiftGen (~> 6.6)
Expand All @@ -24,7 +24,6 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- Alamofire
- KeychainSwift
- Kingfisher
- Sourcery
Expand All @@ -34,17 +33,23 @@ SPEC REPOS:
- Swinject

EXTERNAL SOURCES:
Alamofire:
:git: https://github.com/Alamofire/Alamofire.git
:tag: 5.10.0
SwiftyMocky:
:git: https://github.com/MakeAWishFoundation/SwiftyMocky.git
:tag: 4.2.0

CHECKOUT OPTIONS:
Alamofire:
:git: https://github.com/Alamofire/Alamofire.git
:tag: 5.10.0
SwiftyMocky:
:git: https://github.com/MakeAWishFoundation/SwiftyMocky.git
:tag: 4.2.0

SPEC CHECKSUMS:
Alamofire: f36a35757af4587d8e4f4bfa223ad10be2422b8c
Alamofire: cd0b98508df05796dd2ff278f3bb055a631b5390
KeychainSwift: 007c4647486e4563adca839cf02cef00deb3b670
Kingfisher: bbf78af014cc845cf9a799363f627b5212784165
Sourcery: 6f5fe49b82b7e02e8c65560cbd52e1be67a1af2e
Expand All @@ -54,6 +59,6 @@ SPEC CHECKSUMS:
SwiftyMocky: c5e96e4ff76ec6dbf5a5941aeb039b5a546954a0
Swinject: a827d508c6270da03ec74e558e728917a888fa9b

PODFILE CHECKSUM: b3183e95d2b3bf330c512113a847f9a5485c23a5
PODFILE CHECKSUM: 1873e8ac2c331deb6c08b61ef4cd18d56e060c40

COCOAPODS: 1.15.2
18 changes: 9 additions & 9 deletions Profile/Profile/Data/ProfileRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ class ProfileRepositoryMock: ProfileRepositoryProtocol {

public func enrollmentsStatus() async throws -> [CourseForSync] {
let result = [
DataLayer.EnrollmentsStatusElement(courseID: "1", courseName: "Course 1", isActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "2", courseName: "Course 2", isActive: false),
DataLayer.EnrollmentsStatusElement(courseID: "3", courseName: "Course 3", isActive: false),
DataLayer.EnrollmentsStatusElement(courseID: "4", courseName: "Course 4", isActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "5", courseName: "Course 5", isActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "6", courseName: "Course 6", isActive: false),
DataLayer.EnrollmentsStatusElement(courseID: "7", courseName: "Course 7", isActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "8", courseName: "Course 8", isActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "9", courseName: "Course 9", isActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "1", courseName: "Course 1", recentlyActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "2", courseName: "Course 2", recentlyActive: false),
DataLayer.EnrollmentsStatusElement(courseID: "3", courseName: "Course 3", recentlyActive: false),
DataLayer.EnrollmentsStatusElement(courseID: "4", courseName: "Course 4", recentlyActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "5", courseName: "Course 5", recentlyActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "6", courseName: "Course 6", recentlyActive: false),
DataLayer.EnrollmentsStatusElement(courseID: "7", courseName: "Course 7", recentlyActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "8", courseName: "Course 8", recentlyActive: true),
DataLayer.EnrollmentsStatusElement(courseID: "9", courseName: "Course 9", recentlyActive: true),
]

return result.domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public class CalendarManager: CalendarManagerProtocol {
!fetchedCourses.contains { $0.courseID == course.courseID }
}
let inactiveCourses = fetchedCourses.filter { course in
courseCalendarStates.contains { $0.courseID == course.courseID } && !course.active
courseCalendarStates.contains { $0.courseID == course.courseID } && !course.recentlyActive
}

for course in coursesToDelete {
Expand All @@ -229,11 +229,11 @@ public class CalendarManager: CalendarManagerProtocol {
}

let newlyActiveCourses = fetchedCourses.filter { fetchedCourse in
courseCalendarStates.contains { $0.courseID == fetchedCourse.courseID } && fetchedCourse.active
courseCalendarStates.contains { $0.courseID == fetchedCourse.courseID } && fetchedCourse.recentlyActive
}

return fetchedCourses.filter { course in
courseCalendarStates.contains { $0.courseID == course.courseID } && course.active
courseCalendarStates.contains { $0.courseID == course.courseID } && course.recentlyActive
}
} else {
return fetchedCourses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public struct CoursesToSyncView: View {
ForEach(
Array(
viewModel.coursesForSync.filter({ course in
course.synced == viewModel.synced && (!viewModel.hideInactiveCourses || course.active)
course.synced == viewModel.synced && (!viewModel.hideInactiveCourses || course.recentlyActive)
})
.sorted { $0.active && !$1.active }
.sorted { $0.recentlyActive && !$1.recentlyActive }
.enumerated()
),
id: \.offset
Expand All @@ -104,10 +104,10 @@ public struct CoursesToSyncView: View {
set: { _ in viewModel.toggleSync(for: course) }
),
text: course.name,
color: Theme.Colors.textPrimary.opacity(course.active ? 1 : 0.8)
color: Theme.Colors.textPrimary.opacity(course.recentlyActive ? 1 : 0.8)
)

if !course.active {
if !course.recentlyActive {
Text(ProfileLocalization.CoursesToSync.inactive)
.font(Theme.Fonts.labelSmall)
.foregroundStyle(Theme.Colors.textPrimary.opacity(0.8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
var updatedCourse = course
updatedCourse.synced = courseCalendarStates.contains {
$0.courseID == course.courseID
} && course.active
} && course.recentlyActive
return updatedCourse
}

Expand All @@ -235,7 +235,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
courseID: course.courseID,
courseName: course.name,
courseDates: courseDates,
active: course.active
active: course.recentlyActive
)
} catch {
assignmentStatus = .failed
Expand All @@ -253,7 +253,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
}

private func updateCoursesCount() {
syncingCoursesCount = coursesForSync.filter { $0.active && $0.synced }.count
syncingCoursesCount = coursesForSync.filter { $0.recentlyActive && $0.synced }.count
}

@MainActor
Expand All @@ -266,7 +266,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
return
}
let selectedCourses = await calendarManager.filterCoursesBySelected(fetchedCourses: coursesForSync)
let activeSelectedCourses = selectedCourses.filter { $0.active }
let activeSelectedCourses = selectedCourses.filter { $0.recentlyActive }
assignmentStatus = .loading
for course in activeSelectedCourses {
do {
Expand All @@ -275,7 +275,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
courseID: course.courseID,
courseName: course.name,
courseDates: courseDates,
active: course.active
active: course.recentlyActive
)
} catch {
assignmentStatus = .failed
Expand All @@ -289,7 +289,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
}

private func filterCoursesBySynced() -> [CourseForSync] {
let syncedCourses = coursesForSync.filter { $0.synced && $0.active }
let syncedCourses = coursesForSync.filter { $0.synced && $0.recentlyActive }
return syncedCourses
}

Expand Down Expand Up @@ -328,7 +328,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
}

await calendarManager.syncCourse(courseID: courseID, courseName: courseName, dates: courseDates)
if let index = self.coursesForSync.firstIndex(where: { $0.courseID == courseID && $0.active }) {
if let index = self.coursesForSync.firstIndex(where: { $0.courseID == courseID && $0.recentlyActive }) {
await MainActor.run {
self.coursesForSync[index].synced = true
}
Expand All @@ -354,7 +354,7 @@ public class DatesAndCalendarViewModel: ObservableObject {
}

func toggleSync(for course: CourseForSync) {
guard course.active else { return }
guard course.recentlyActive else { return }
if coursesForSyncBeforeChanges.isEmpty {
coursesForSyncBeforeChanges = coursesForSync
}
Expand Down

0 comments on commit 8cfe33f

Please sign in to comment.