Skip to content

Commit

Permalink
✨ (LekaApp): Use LibraryManagerVM instead of RootAccountVM
Browse files Browse the repository at this point in the history
  • Loading branch information
macteuts committed Dec 18, 2024
1 parent 0184a35 commit 5f9a6cc
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ struct CategoryLibraryView: View {
if self.authManagerViewModel.userAuthenticationState == .loggedIn {
switch self.category {
case .libraryCurriculums:
LibraryCurriculumsView(viewModel: self.rootAccountViewModel)
LibraryCurriculumsView(viewModel: self.libraryManagerViewModel)
.navigationTitle(String(l10n.MainView.Sidebar.CategoryLabel.libraryCurriculums.characters))
case .libraryStories:
LibraryStoriesView(viewModel: self.rootAccountViewModel)
LibraryStoriesView(viewModel: self.libraryManagerViewModel)
.navigationTitle(String(l10n.MainView.Sidebar.CategoryLabel.libraryStories.characters))
default:
LibraryActivitiesView(viewModel: self.rootAccountViewModel)
LibraryActivitiesView(viewModel: self.libraryManagerViewModel)
.navigationTitle(String(l10n.MainView.Sidebar.CategoryLabel.libraryActivities.characters))
}
} else {
Expand All @@ -29,7 +29,7 @@ struct CategoryLibraryView: View {
}
}

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@ObservedObject var authManagerViewModel = AuthManagerViewModel.shared
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI
struct LibraryActivitiesView: View {
// MARK: Lifecycle

init(viewModel: RootAccountManagerViewModel) {
init(viewModel: LibraryManagerViewModel) {
self.viewModel = viewModel
}

Expand All @@ -38,7 +38,7 @@ struct LibraryActivitiesView: View {
// MARK: Private

@ObservedObject private var navigation: Navigation = .shared
@ObservedObject private var viewModel: RootAccountManagerViewModel
@ObservedObject private var viewModel: LibraryManagerViewModel
@ObservedObject private var authManagerViewModel: AuthManagerViewModel = .shared

private var activities: [Activity] {
Expand All @@ -52,7 +52,7 @@ struct LibraryActivitiesView: View {
}

#Preview {
let viewModel = RootAccountManagerViewModel()
let viewModel = LibraryManagerViewModel()
NavigationStack {
LibraryActivitiesView(viewModel: viewModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
struct LibraryCurriculumsView: View {
// MARK: Lifecycle

init(viewModel: RootAccountManagerViewModel) {
init(viewModel: LibraryManagerViewModel) {
self.viewModel = viewModel
}

Expand All @@ -37,7 +37,7 @@ struct LibraryCurriculumsView: View {
// MARK: Private

@ObservedObject private var navigation: Navigation = .shared
@ObservedObject private var viewModel: RootAccountManagerViewModel
@ObservedObject private var viewModel: LibraryManagerViewModel
@ObservedObject private var authManagerViewModel: AuthManagerViewModel = .shared

private var curriculums: [Curriculum] {
Expand All @@ -51,6 +51,6 @@ struct LibraryCurriculumsView: View {
}

#Preview {
let viewModel = RootAccountManagerViewModel()
let viewModel = LibraryManagerViewModel()
LibraryCurriculumsView(viewModel: viewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI
struct LibraryStoriesView: View {
// MARK: Lifecycle

init(viewModel: RootAccountManagerViewModel) {
init(viewModel: LibraryManagerViewModel) {
self.viewModel = viewModel
}

Expand All @@ -38,7 +38,7 @@ struct LibraryStoriesView: View {
// MARK: Private

@ObservedObject private var navigation: Navigation = .shared
@ObservedObject private var viewModel: RootAccountManagerViewModel
@ObservedObject private var viewModel: LibraryManagerViewModel
@ObservedObject private var authManagerViewModel: AuthManagerViewModel = .shared

private var stories: [Story] {
Expand All @@ -52,7 +52,7 @@ struct LibraryStoriesView: View {
}

#Preview {
let viewModel = RootAccountManagerViewModel()
let viewModel = LibraryManagerViewModel()
NavigationStack {
LibraryStoriesView(viewModel: viewModel)
}
Expand Down
4 changes: 2 additions & 2 deletions Apps/LekaApp/Sources/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ struct SettingsView: View {
@ObservedObject private var styleManager: StyleManager = .shared
@ObservedObject private var navigation = Navigation.shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()

private func reset() {
self.caregiverManager.resetData()
self.carereceiverManager.resetData()
self.rootAccountViewModel.resetData()
self.libraryManagerViewModel.resetData()
self.styleManager.accentColor = DesignKitAsset.Colors.lekaDarkBlue.swiftUIColor
self.styleManager.colorScheme = .light
}
Expand Down
8 changes: 4 additions & 4 deletions Modules/ContentKit/Sources/Views/ActivityDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ public struct ActivityDetailsView: View {
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
ToolbarItem {
Menu {
if self.rootAccountViewModel.isActivitySaved(activityID: self.activity.uuid) {
if self.libraryManagerViewModel.isActivitySaved(activityID: self.activity.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedActivity(activityID: self.activity.uuid)
self.libraryManagerViewModel.removeSavedActivity(activityID: self.activity.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")
}
} else {
Button {
self.rootAccountViewModel.addSavedActivity(
self.libraryManagerViewModel.addSavedActivity(
activityID: self.activity.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -176,7 +176,7 @@ public struct ActivityDetailsView: View {

@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()

private let activity: Activity
Expand Down
8 changes: 4 additions & 4 deletions Modules/ContentKit/Sources/Views/ActivityListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public struct ActivityListView: View {
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
Button {} label: {
Menu {
if self.rootAccountViewModel.isActivitySaved(activityID: activity.uuid) {
if self.libraryManagerViewModel.isActivitySaved(activityID: activity.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedActivity(activityID: activity.uuid)
self.libraryManagerViewModel.removeSavedActivity(activityID: activity.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")
}
} else {
Button {
self.rootAccountViewModel.addSavedActivity(
self.libraryManagerViewModel.addSavedActivity(
activityID: activity.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -155,7 +155,7 @@ public struct ActivityListView: View {

@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()
}

Expand Down
8 changes: 4 additions & 4 deletions Modules/ContentKit/Sources/Views/CurriculumDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ public struct CurriculumDetailsView: View {
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
ToolbarItem {
Menu {
if self.rootAccountViewModel.isCurriculumSaved(curriculumID: self.curriculum.uuid) {
if self.libraryManagerViewModel.isCurriculumSaved(curriculumID: self.curriculum.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedCurriculum(curriculumID: self.curriculum.uuid)
self.libraryManagerViewModel.removeSavedCurriculum(curriculumID: self.curriculum.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")
}
} else {
Button {
self.rootAccountViewModel.addSavedCurriculum(
self.libraryManagerViewModel.addSavedCurriculum(
curriculumID: self.curriculum.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -188,7 +188,7 @@ public struct CurriculumDetailsView: View {
@State private var isDescriptionExpanded = false
@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()

private let curriculum: Curriculum
Expand Down
10 changes: 5 additions & 5 deletions Modules/ContentKit/Sources/Views/CurriculumGroupboxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public struct CurriculumGroupboxView: View {
Button {}
label: {
Menu {
if self.rootAccountViewModel.isCurriculumSaved(curriculumID: self.curriculum.uuid) {
if self.libraryManagerViewModel.isCurriculumSaved(curriculumID: self.curriculum.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedCurriculum(curriculumID: self.curriculum.uuid)
self.libraryManagerViewModel.removeSavedCurriculum(curriculumID: self.curriculum.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")
}
} else {
Button {
self.rootAccountViewModel.addSavedCurriculum(
self.libraryManagerViewModel.addSavedCurriculum(
curriculumID: self.curriculum.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -87,7 +87,7 @@ public struct CurriculumGroupboxView: View {
Image(systemName: "checkmark.circle.fill")
.font(.title3)
.foregroundStyle(Color.secondary)
.opacity(self.rootAccountViewModel.isCurriculumSaved(curriculumID: self.curriculum.uuid) ? 1 : 0)
.opacity(self.libraryManagerViewModel.isCurriculumSaved(curriculumID: self.curriculum.uuid) ? 1 : 0)

Spacer()

Expand All @@ -111,7 +111,7 @@ public struct CurriculumGroupboxView: View {

@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()

private let curriculum: Curriculum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public struct LibraryActivityListView: View {
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
Button {} label: {
Menu {
if self.rootAccountViewModel.isActivitySaved(activityID: activity.uuid) {
if self.libraryManagerViewModel.isActivitySaved(activityID: activity.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedActivity(activityID: activity.uuid)
self.libraryManagerViewModel.removeSavedActivity(activityID: activity.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")
}
} else {
Button {
self.rootAccountViewModel.addSavedActivity(
self.libraryManagerViewModel.addSavedActivity(
activityID: activity.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -154,7 +154,7 @@ public struct LibraryActivityListView: View {

@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()
}

Expand Down
8 changes: 4 additions & 4 deletions Modules/ContentKit/Sources/Views/StoryDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ public struct StoryDetailsView: View {
if let currentCaregiverID = self.caregiverManagerViewModel.currentCaregiver?.id {
ToolbarItem {
Menu {
if self.rootAccountViewModel.isStorySaved(storyID: self.story.uuid) {
if self.libraryManagerViewModel.isStorySaved(storyID: self.story.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedStory(storyID: self.story.uuid)
self.libraryManagerViewModel.removeSavedStory(storyID: self.story.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")
}
} else {
Button {
self.rootAccountViewModel.addSavedStory(
self.libraryManagerViewModel.addSavedStory(
storyID: self.story.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -167,7 +167,7 @@ public struct StoryDetailsView: View {

@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()

private let story: Story
Expand Down
8 changes: 4 additions & 4 deletions Modules/ContentKit/Sources/Views/StoryListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public struct StoryListView: View {
Button {}
label: {
Menu {
if self.rootAccountViewModel.isStorySaved(storyID: story.uuid) {
if self.libraryManagerViewModel.isStorySaved(storyID: story.uuid) {
Button(role: .destructive) {
self.rootAccountViewModel.removeSavedStory(storyID: story.uuid)
self.libraryManagerViewModel.removeSavedStory(storyID: story.uuid)
} label: {
Label(String(l10n.Library.MenuActions.removeFromlibraryButtonLabel.characters), systemImage: "trash")

Check warning on line 73 in Modules/ContentKit/Sources/Views/StoryListView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 153 characters (line_length)
}
} else {
Button {
self.rootAccountViewModel.addSavedStory(
self.libraryManagerViewModel.addSavedStory(
storyID: story.uuid,
caregiverID: currentCaregiverID
)
Expand Down Expand Up @@ -126,7 +126,7 @@ public struct StoryListView: View {

@ObservedObject private var styleManager: StyleManager = .shared

@StateObject private var rootAccountViewModel = RootAccountManagerViewModel()
@StateObject private var libraryManagerViewModel = LibraryManagerViewModel()
@StateObject private var caregiverManagerViewModel = CaregiverManagerViewModel()
}

Expand Down

0 comments on commit 5f9a6cc

Please sign in to comment.