Skip to content

Commit

Permalink
🧐 (AccountKit): Adapt and test DataModels and refactor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
macteuts committed Feb 22, 2024
1 parent 7682ff2 commit 9f1b188
Show file tree
Hide file tree
Showing 26 changed files with 509 additions and 114 deletions.
8 changes: 4 additions & 4 deletions Apps/LekaApp/Sources/_NEWCodeBase/Models/CompanyModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ protocol Profile: Identifiable {
var avatar: String { get set }
}

// MARK: - Caregiver
// MARK: - Caregiver_OLD

struct Caregiver: Profile {
struct Caregiver_OLD: Profile {
// MARK: Lifecycle

init(name: String = "",
Expand All @@ -43,9 +43,9 @@ struct Caregiver: Profile {
var preferredAccentColor: Color
}

// MARK: - Carereceiver
// MARK: - Carereceiver_OLD

struct Carereceiver: Profile, Hashable {
struct Carereceiver_OLD: Profile, Hashable {
// MARK: Lifecycle

init(name: String = "", avatar: String = "", reinforcer: Int = 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension EditCaregiverView {
struct AccentColorRow: View {
// MARK: Internal

@Binding var caregiver: Caregiver
@Binding var caregiver: Caregiver_OLD

var body: some View {
HStack {
Expand Down Expand Up @@ -66,6 +66,6 @@ extension EditCaregiverView {

#Preview {
Form {
EditCaregiverView.AccentColorRow(caregiver: .constant(Caregiver()))
EditCaregiverView.AccentColorRow(caregiver: .constant(Caregiver_OLD()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension EditCaregiverView {
struct AppearanceRow: View {
// MARK: Internal

@Binding var caregiver: Caregiver
@Binding var caregiver: Caregiver_OLD

var body: some View {
HStack(spacing: 10) {
Expand All @@ -38,6 +38,6 @@ extension EditCaregiverView {

#Preview {
Form {
EditCaregiverView.AppearanceRow(caregiver: .constant(Caregiver()))
EditCaregiverView.AppearanceRow(caregiver: .constant(Caregiver_OLD()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import SwiftUI
struct EditCaregiverView: View {
// MARK: Lifecycle

init(modifiedCaregiver: Caregiver) {
init(modifiedCaregiver: Caregiver_OLD) {
self._modifiedCaregiver = State(wrappedValue: modifiedCaregiver)
self.initialColorScheme = modifiedCaregiver.preferredColorScheme
self.initialAccentColor = modifiedCaregiver.preferredAccentColor
}

// MARK: Internal

@State var modifiedCaregiver: Caregiver
@State var modifiedCaregiver: Caregiver_OLD
var initialColorScheme: ColorScheme
var initialAccentColor: Color

Expand Down Expand Up @@ -113,5 +113,5 @@ struct EditCaregiverView: View {
}

#Preview {
EditCaregiverView(modifiedCaregiver: Caregiver())
EditCaregiverView(modifiedCaregiver: Caregiver_OLD())
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct EditCarereceiverView: View {
// MARK: Internal

@Binding var modifiedCarereceiver: Carereceiver
@Binding var modifiedCarereceiver: Carereceiver_OLD

var body: some View {
NavigationStack {
Expand Down Expand Up @@ -81,5 +81,5 @@ struct EditCarereceiverView: View {
}

#Preview {
EditCarereceiverView(modifiedCarereceiver: .constant(Carereceiver()))
EditCarereceiverView(modifiedCarereceiver: .constant(Carereceiver_OLD()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct CarereceiverView: View {
// MARK: Internal

@State var carereceiver: Carereceiver
@State var carereceiver: Carereceiver_OLD

var body: some View {
VStack {
Expand Down Expand Up @@ -90,5 +90,5 @@ extension l10n {
// swiftlint:enable line_length

#Preview {
CarereceiverView(carereceiver: Carereceiver(name: "Peet", avatar: DesignKitAsset.Avatars.avatarsBoy1a.name, reinforcer: 2))
CarereceiverView(carereceiver: Carereceiver_OLD(name: "Peet", avatar: DesignKitAsset.Avatars.avatarsBoy1a.name, reinforcer: 2))
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ extension l10n {
})
.onAppear {
let rootOwnerViewModel = RootOwnerViewModel.shared
rootOwnerViewModel.currentCaregiver = Caregiver(name: "Joe", avatar: "avatars_boy-1a")
rootOwnerViewModel.currentCaregiver = Caregiver_OLD(name: "Joe", avatar: "avatars_boy-1a")
}
}
101 changes: 93 additions & 8 deletions Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/NewsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,108 @@
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import AccountKit
import LocalizationKit
import SwiftUI

// MARK: - NewsView

struct NewsView: View {
@ObservedObject var rootOwnerViewModel: RootOwnerViewModel = .shared
// MARK: Internal

@StateObject var caregiverViewModel = CaregiverManagerViewModel()
@StateObject var carereceiversViewModel = CarereceiverManagerViewModel()

var body: some View {
VStack {
Text("Hello, What's new!")
.font(.largeTitle)
.bold()
HStack {
self.caregiversTests
Divider()
self.carereceiversTests
}
}
}

#Preview {
NewsView()
// MARK: Private

@State private var caregiverID = ""
@State private var carereceiverID = ""
private var caregiverManager = CaregiverManager.shared
private var carereceiverManager = CarereceiverManager.shared

private var caregiversTests: some View {
VStack(spacing: 20) {
Button("Create Caregiver") {
let newCaregiver = Caregiver(
firstName: "John",
lastName: "Doe",
email: "[email protected]",
avatar: "avatarURL",
professions: ["Nurse"],
colorScheme: .light,
colorTheme: .blue
)

self.caregiverManager.addCaregiver(caregiver: newCaregiver)
}

TextField("Enter Document ID", text: self.$caregiverID)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button("Fetch Caregiver") {
self.caregiverManager.fetchCaregiver(documentID: self.caregiverID)
}

Button("Update Caregiver") {
guard self.caregiverViewModel.currentCaregiver != nil else {
print("ID is nil... No Caregiver")
return
}
var updatedCaregiver = self.caregiverViewModel.currentCaregiver!
updatedCaregiver.firstName = "Updated"
updatedCaregiver.lastName = "caregiver"

self.caregiverManager.updateAndSelectCaregiver(caregiver: &updatedCaregiver)
}

if let caregiver = caregiverViewModel.currentCaregiver {
Text("Fetched: \(caregiver.firstName) \(caregiver.lastName)")
}
}
.padding()
}

private var carereceiversTests: some View {
VStack(spacing: 20) {
Button("Create Carereceiver") {
let newCarereceiver = Carereceiver(username: "Bobby", avatar: "avatar", reinforcer: "rainbow")

self.carereceiverManager.addCarereceiver(carereceiver: newCarereceiver)
}

TextField("Enter Document ID", text: self.$carereceiverID)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button("Fetch Carereceiver") {
self.carereceiverManager.fetchCarereceiver(documentID: self.carereceiverID)
}

Button("Update Carereceiver") {
guard self.carereceiversViewModel.currentCarereceiver != nil else {
print("ID is nil... No Carereceiver")
return
}
var updatedCarereceiver = self.carereceiversViewModel.currentCarereceiver!
updatedCarereceiver.username = "Updated"
updatedCarereceiver.reinforcer = "Carereceiver"

self.carereceiverManager.updateAndSelectCarereceiver(carereceiver: &updatedCarereceiver)
}

if let carereceiver = carereceiversViewModel.currentCarereceiver {
Text("Fetched: \(carereceiver.username) \(carereceiver.reinforcer)")
}
}
.padding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class RootOwnerViewModel: ObservableObject {

static let shared = RootOwnerViewModel()

@Published var currentCaregiver: Caregiver?
@Published var currentCarereceiver: Carereceiver?
@Published var currentCaregiver: Caregiver_OLD?
@Published var currentCarereceiver: Carereceiver_OLD?

@Published var isSettingsViewPresented = false

Expand All @@ -29,24 +29,24 @@ class RootOwnerViewModel: ObservableObject {
@Published var showConfirmDisconnection: Bool = false
@Published var showConfirmDeleteAccount: Bool = false

@Published var mockCaregiversSet: [Caregiver] = [
Caregiver(name: "Chantal", avatar: DesignKitAsset.Avatars.avatarsBoy4f.name, professions: [Professions.list[6]]),
Caregiver(name: "Gaëtan", avatar: DesignKitAsset.Avatars.avatarsLekaSunglassesBlue.name, professions: [Professions.list[9]], colorScheme: .dark, accentColor: .green),
Caregiver(name: "Fabrizio", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsFarmBirdYellow0071.name, professions: [Professions.list[10]]),
Caregiver(name: "Hakima", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsPearYellow00FC.name, professions: [Professions.list[10], Professions.list[1]]),
Caregiver(name: "Eric", avatar: DesignKitAsset.Avatars.avatarsBoy2a.name, professions: [Professions.list[10]]),
Caregiver(name: "Razmo", avatar: DesignKitAsset.Avatars.avatarsBoy3b.name, professions: [Professions.list[5]], colorScheme: .dark, accentColor: .orange),
Caregiver(name: "Corinne", avatar: DesignKitAsset.Avatars.avatarsGirl1d.name, professions: [Professions.list[4]]),
Caregiver(name: "Alphonso", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsAppleRed0101.name, professions: [Professions.list[0]]),
Caregiver(name: "Gargantua", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsCherryRed00FF.name, professions: [Professions.list[2]]),
@Published var mockCaregiversSet: [Caregiver_OLD] = [
Caregiver_OLD(name: "Chantal", avatar: DesignKitAsset.Avatars.avatarsBoy4f.name, professions: [Professions.list[6]]),
Caregiver_OLD(name: "Gaëtan", avatar: DesignKitAsset.Avatars.avatarsLekaSunglassesBlue.name, professions: [Professions.list[9]], colorScheme: .dark, accentColor: .green),

Check warning on line 34 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/RootOwnerViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 178 characters (line_length)
Caregiver_OLD(name: "Fabrizio", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsFarmBirdYellow0071.name, professions: [Professions.list[10]]),

Check warning on line 35 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/RootOwnerViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 157 characters (line_length)
Caregiver_OLD(name: "Hakima", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsPearYellow00FC.name, professions: [Professions.list[10], Professions.list[1]]),

Check warning on line 36 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/RootOwnerViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 176 characters (line_length)
Caregiver_OLD(name: "Eric", avatar: DesignKitAsset.Avatars.avatarsBoy2a.name, professions: [Professions.list[10]]),
Caregiver_OLD(name: "Razmo", avatar: DesignKitAsset.Avatars.avatarsBoy3b.name, professions: [Professions.list[5]], colorScheme: .dark, accentColor: .orange),

Check warning on line 38 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/RootOwnerViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 165 characters (line_length)
Caregiver_OLD(name: "Corinne", avatar: DesignKitAsset.Avatars.avatarsGirl1d.name, professions: [Professions.list[4]]),
Caregiver_OLD(name: "Alphonso", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsAppleRed0101.name, professions: [Professions.list[0]]),

Check warning on line 40 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/RootOwnerViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 154 characters (line_length)
Caregiver_OLD(name: "Gargantua", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsCherryRed00FF.name, professions: [Professions.list[2]]),

Check warning on line 41 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/RootOwnerViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 156 characters (line_length)
]

@Published var mockCarereceiversSet: [Carereceiver] = [
Carereceiver(name: "Peet", avatar: DesignKitAsset.Avatars.avatarsLekaAstronaut.name, reinforcer: 1),
Carereceiver(name: "Rounhaa", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsForestSquirrelOrange005C.name, reinforcer: 3),
Carereceiver(name: "Selug", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsSeaCrabRed003E.name, reinforcer: 4),
Carereceiver(name: "Luther", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsAppleRed0101.name, reinforcer: 5),
Carereceiver(name: "Abel", avatar: DesignKitAsset.Avatars.avatarsBoy1g.name, reinforcer: 2),
@Published var mockCarereceiversSet: [Carereceiver_OLD] = [
Carereceiver_OLD(name: "Peet", avatar: DesignKitAsset.Avatars.avatarsLekaAstronaut.name, reinforcer: 1),
Carereceiver_OLD(name: "Rounhaa", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsForestSquirrelOrange005C.name, reinforcer: 3),
Carereceiver_OLD(name: "Selug", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsSeaCrabRed003E.name, reinforcer: 4),
Carereceiver_OLD(name: "Luther", avatar: DesignKitAsset.Avatars.avatarsPictogramsFoodsFruitsAppleRed0101.name, reinforcer: 5),
Carereceiver_OLD(name: "Abel", avatar: DesignKitAsset.Avatars.avatarsBoy1g.name, reinforcer: 2),
]

func getReinforcerFor(index: Int) -> UIImage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension ProfessionPicker {
struct ProfessionTag: View {
@ObservedObject private var rootOwnerViewModel: RootOwnerViewModel = .shared
@State var profession: Profession
@Binding var caregiver: Caregiver
@Binding var caregiver: Caregiver_OLD

var body: some View {
Button {
Expand All @@ -34,6 +34,6 @@ extension ProfessionPicker {
#Preview {
ProfessionPicker.ProfessionTag(
profession: Professions.list[8],
caregiver: .constant(Caregiver(professions: [Professions.list[0], Professions.list[3]]))
caregiver: .constant(Caregiver_OLD(professions: [Professions.list[0], Professions.list[3]]))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ProfessionPicker: View {

@Environment(\.dismiss) var dismiss

@Binding var caregiver: Caregiver
@Binding var caregiver: Caregiver_OLD

var body: some View {
List(Professions.list, id: \.self, selection: self.$selectedProfessions) { profession in
Expand Down Expand Up @@ -66,6 +66,6 @@ struct ProfessionPicker: View {

#Preview {
NavigationStack {
ProfessionPicker(caregiver: .constant(Caregiver()))
ProfessionPicker(caregiver: .constant(Caregiver_OLD()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DesignKit
import SwiftUI

struct CaregiverAvatarCell: View {
let caregiver: Caregiver
let caregiver: Caregiver_OLD

var body: some View {
VStack(spacing: 10) {
Expand All @@ -23,5 +23,5 @@ struct CaregiverAvatarCell: View {
}

#Preview {
CaregiverAvatarCell(caregiver: Caregiver(name: "Chantal", avatar: DesignKitAsset.Avatars.avatarsBoy4f.name, professions: []))
CaregiverAvatarCell(caregiver: Caregiver_OLD(name: "Chantal", avatar: DesignKitAsset.Avatars.avatarsBoy4f.name, professions: []))
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct CarereceiverAvatarCell: View {

@ObservedObject private var rootOwnerViewModel: RootOwnerViewModel = .shared

let carereceiver: Carereceiver
let carereceiver: Carereceiver_OLD

var body: some View {
VStack(spacing: 10) {
Expand Down Expand Up @@ -45,5 +45,5 @@ struct CarereceiverAvatarCell: View {
}

#Preview {
CarereceiverAvatarCell(carereceiver: Carereceiver(name: "Chantal", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsSavannaKangarooBrown0078.name, reinforcer: 2))
CarereceiverAvatarCell(carereceiver: Carereceiver_OLD(name: "Chantal", avatar: DesignKitAsset.Avatars.avatarsPictogramsAnimalsSavannaKangarooBrown0078.name, reinforcer: 2))

Check warning on line 48 in Apps/LekaApp/Sources/_NEWCodeBase/Views/Profiles/CarereceiverAvatarCell.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Line should be 150 characters or less; currently it has 176 characters (line_length)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct CarereceiverPicker: View {
.sheet(isPresented: self.$isCarereceiverCreationPresented) {
CreateCarereceiverView(isPresented: self.$isCarereceiverCreationPresented) {}
}
.navigationDestination(for: Carereceiver.self) { carereceiver in
.navigationDestination(for: Carereceiver_OLD.self) { carereceiver in
CarereceiverView(carereceiver: carereceiver)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct CreateCaregiverView: View {
// MARK: Internal

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

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct CreateCarereceiverView: View {
// MARK: Internal

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

var body: some View {
Expand Down
Loading

0 comments on commit 9f1b188

Please sign in to comment.