Skip to content

Commit

Permalink
♻️ (LekaApp): Refactor Caregiver in rootOwnerViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Feb 7, 2024
1 parent 1f651e5 commit c1da810
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class RootOwnerViewModel: ObservableObject {
static let shared = RootOwnerViewModel()

@Published var currentCompany: Company?

@Published var bufferCaregiver = Caregiver()
@Published var bufferCarereceiver = Carereceiver()
@Published var currentCaregiver: Caregiver?

@Published var isWelcomeViewPresented = true
@Published var isSettingsViewPresented = false
Expand All @@ -46,5 +44,6 @@ class RootOwnerViewModel: ObservableObject {

func disconnect() {
self.currentCompany = nil
self.currentCaregiver = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension ProfessionPicker {
struct ProfessionTag: View {
@ObservedObject private var rootOwnerViewModel: RootOwnerViewModel = .shared
@State var profession: Caregiver.Profession
@Binding var caregiver: Caregiver

var body: some View {
Button {
Expand All @@ -19,7 +20,7 @@ extension ProfessionPicker {

Image(systemName: "multiply.square.fill")
.onTapGesture {
self.rootOwnerViewModel.bufferCaregiver.professions.removeAll(where: { self.profession == $0 })
self.caregiver.professions.removeAll(where: { self.profession == $0 })
}
}
}
Expand All @@ -31,5 +32,8 @@ extension ProfessionPicker {
}

#Preview {
ProfessionPicker.ProfessionTag(profession: Caregiver.Profession.occupationalTherapist)
ProfessionPicker.ProfessionTag(
profession: Caregiver.Profession.occupationalTherapist,
caregiver: .constant(Caregiver(professions: [Caregiver.Profession.occupationalTherapist, Caregiver.Profession.motorTherapist]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import SwiftUI
struct ProfessionPicker: View {
// MARK: Internal

@Binding var caregiver: Caregiver
@Environment(\.dismiss) var dismiss

var body: some View {
ListView(selectedProfessions: self.$selectedProfessions)
.onAppear {
self.selectedProfessions = self.rootOwnerViewModel.bufferCaregiver.professions
self.selectedProfessions = self.caregiver.professions
}
.safeAreaInset(edge: .bottom) {
TextFieldDefault(label: String(l10n.ProfessionPicker.otherLabel.characters), entry: self.$otherProfessionText)
Expand All @@ -30,7 +31,7 @@ struct ProfessionPicker: View {
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
self.rootOwnerViewModel.bufferCaregiver.professions = self.selectedProfessions
self.caregiver.professions = self.selectedProfessions
self.dismiss()
} label: {
Label(String(l10n.ProfessionPicker.validateButton.characters), systemImage: "checkmark.circle")
Expand All @@ -42,13 +43,12 @@ struct ProfessionPicker: View {

// MARK: Private

@ObservedObject private var rootOwnerViewModel: RootOwnerViewModel = .shared
@State private var otherProfessionText: String = ""
@State private var selectedProfessions: [Caregiver.Profession] = []
}

// MARK: - ProfessionPicker_Previews

#Preview {
ProfessionPicker()
ProfessionPicker(caregiver: .constant(Caregiver()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct CaregiverAvatarCell: View {
var body: some View {
Button {
// TODO: (@team) - Add caregiver selection logic w/ Firebase
self.rootOwnerViewModel.currentCaregiver = self.caregiver
self.rootOwnerViewModel.isWelcomeViewPresented = false
} label: {
VStack(spacing: 10) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct CaregiverPicker: View {

@State private var selected: String = ""
@State private var isCaregiverCreationPresented: Bool = false
@State private var navigateToTeacherCreation: Bool = false

private var addCaregiverButton: some View {
Button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct CreateCaregiverView: View {
// MARK: Internal

@Binding var isPresented: Bool
@State private var newCaregiver = Caregiver()
var onDismissAction: () -> Void

var body: some View {
Expand All @@ -21,7 +22,7 @@ struct CreateCaregiverView: View {
self.avatarNavigationLink

TextFieldDefault(label: String(l10n.CaregiverCreation.caregiverNameLabel.characters),
entry: self.$rootOwnerViewModel.bufferCaregiver.name)
entry: self.$newCaregiver.name)
.frame(width: 400)

self.professionNavigationLink
Expand All @@ -33,9 +34,9 @@ struct CreateCaregiverView: View {
}
// TODO: (@team) : add the caregiver profile to the account
// TODO: (@team) : assign the caregiver profile as the current selected one
self.rootOwnerViewModel.mockCaregiversSet.append(self.rootOwnerViewModel.bufferCaregiver)
self.rootOwnerViewModel.mockCaregiversSet.append(self.newCaregiver)
}
.disabled(self.rootOwnerViewModel.bufferCaregiver.name.isEmpty)
.disabled(self.newCaregiver.name.isEmpty)
.buttonStyle(.borderedProminent)
}
.padding()
Expand All @@ -50,10 +51,10 @@ struct CreateCaregiverView: View {

private var avatarNavigationLink: some View {
NavigationLink {
AvatarPicker(avatar: self.$rootOwnerViewModel.bufferCaregiver.avatar)
AvatarPicker(avatar: self.$newCaregiver.avatar)
} label: {
VStack(spacing: 15) {
AvatarPicker.ButtonLabel(image: self.rootOwnerViewModel.bufferCaregiver.avatar)
AvatarPicker.ButtonLabel(image: self.newCaregiver.avatar)
Text(l10n.CaregiverCreation.avatarChoiceButton)
// TODO: (@ui/ux) - Design System - replace with Leka font
.font(.headline)
Expand All @@ -71,15 +72,15 @@ struct CreateCaregiverView: View {
Spacer()

NavigationLink {
ProfessionPicker()
ProfessionPicker(caregiver: self.$newCaregiver)
} label: {
Label(String(l10n.CaregiverCreation.professionAddButton.characters), systemImage: "plus")
}
}

if !self.rootOwnerViewModel.bufferCaregiver.professions.isEmpty {
ForEach(self.rootOwnerViewModel.bufferCaregiver.professions, id: \.self) { profession in
ProfessionPicker.ProfessionTag(profession: profession)
if !self.newCaregiver.professions.isEmpty {
ForEach(self.newCaregiver.professions, id: \.self) { profession in
ProfessionPicker.ProfessionTag(profession: profession, caregiver: self.$newCaregiver)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct CreateCarereceiverView: View {
// MARK: Internal

@Binding var isPresented: Bool
@State private var newCarereceiver = Carereceiver()
var onDismissAction: () -> Void

var body: some View {
Expand All @@ -21,7 +22,7 @@ struct CreateCarereceiverView: View {
self.avatarNavigationLink

TextFieldDefault(label: String(l10n.CarereceiverCreation.carereceiverNameLabel.characters),
entry: self.$rootOwnerViewModel.bufferCarereceiver.name)
entry: self.$newCarereceiver.name)
.frame(width: 400)

Button(String(l10n.CarereceiverCreation.registerProfilButton.characters)) {
Expand All @@ -32,7 +33,7 @@ struct CreateCarereceiverView: View {
// TODO: (@team) : add the carereceiver profile to the account
// TODO: (@team) : assign the carereceiver profile as the current selected one
}
.disabled(self.rootOwnerViewModel.bufferCarereceiver.name.isEmpty)
.disabled(self.newCarereceiver.name.isEmpty)
.buttonStyle(.borderedProminent)
}
.padding()
Expand All @@ -47,10 +48,10 @@ struct CreateCarereceiverView: View {

private var avatarNavigationLink: some View {
NavigationLink {
AvatarPicker(avatar: self.$rootOwnerViewModel.bufferCarereceiver.avatar)
AvatarPicker(avatar: self.$newCarereceiver.avatar)
} label: {
VStack(spacing: 15) {
AvatarPicker.ButtonLabel(image: self.rootOwnerViewModel.bufferCarereceiver.avatar)
AvatarPicker.ButtonLabel(image: self.newCarereceiver.avatar)
Text(l10n.CarereceiverCreation.avatarChoiceButton)
// TODO: (@ui/ux) - Design System - replace with Leka font
.font(.headline)
Expand Down

0 comments on commit c1da810

Please sign in to comment.