Skip to content

Commit

Permalink
🔀 Merge branch 'hugo/bugfix/Refactor-Navigation-flow-for-caregiver-ca…
Browse files Browse the repository at this point in the history
…tegory'
  • Loading branch information
ladislas committed Feb 14, 2024
2 parents 582465e + 56ead3c commit a8a010c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Caregiver: Profile {

// MARK: - Carereceiver

struct Carereceiver: Profile {
struct Carereceiver: 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 @@ -11,7 +11,7 @@ import SwiftUI
struct CarereceiverSettingsView: View {
// MARK: Internal

@State var modifiedCarereceiver: Carereceiver
@Binding var modifiedCarereceiver: Carereceiver

var body: some View {
NavigationStack {
Expand Down Expand Up @@ -54,13 +54,11 @@ struct CarereceiverSettingsView: View {
}
}
}
.preferredColorScheme(self.styleManager.colorScheme)
}

// MARK: Private

@ObservedObject private var rootOwnerViewModel: RootOwnerViewModel = .shared
@ObservedObject private var styleManager: StyleManager = .shared
@State private var isAvatarPickerPresented: Bool = false

private var avatarPickerButton: some View {
Expand All @@ -81,5 +79,5 @@ struct CarereceiverSettingsView: View {
}

#Preview {
CarereceiverSettingsView(modifiedCarereceiver: Carereceiver())
CarereceiverSettingsView(modifiedCarereceiver: .constant(Carereceiver()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@ import SwiftUI
struct CarereceiverView: View {
// MARK: Internal

@State var carereceiver: Carereceiver

var body: some View {
Button {
self.rootOwnerViewModel.isCarereceiverSettingsViewPresented = true
} label: {
CarereceiverAvatarCell(carereceiver: self.rootOwnerViewModel.currentCarereceiver!)
}
.onDisappear {
self.rootOwnerViewModel.currentCarereceiver = nil
CarereceiverAvatarCell(carereceiver: self.carereceiver)
}
.sheet(isPresented: self.$rootOwnerViewModel.isCarereceiverSettingsViewPresented) {
CarereceiverSettingsView(modifiedCarereceiver: self.rootOwnerViewModel.currentCarereceiver!)
CarereceiverSettingsView(modifiedCarereceiver: self.$carereceiver)
}
}

// MARK: Private

@ObservedObject private var rootOwnerViewModel: RootOwnerViewModel = .shared
@ObservedObject private var styleManager: StyleManager = .shared
}

#Preview {
CarereceiverView()
CarereceiverView(carereceiver: Carereceiver())
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ struct MainView: View {

case .carereceivers:
CarereceiverPicker()
.navigationDestination(isPresented: .constant(self.rootOwnerViewModel.isCarereceiverSelected)) {
CarereceiverView()
}

case .none:
Text("Select a category")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,31 @@ struct CarereceiverPicker: View {
ScrollView(showsIndicators: false) {
LazyVGrid(columns: self.columns, spacing: 40) {
ForEach(self.rootOwnerViewModel.mockCarereceiversSet) { carereceiver in
Button {
// TODO: (@team) - Add carereceiver selection logic w/ Firebase
self.rootOwnerViewModel.currentCarereceiver = carereceiver
self.rootOwnerViewModel.isCarereceiverPickerViewPresented = false
} label: {
NavigationLink(value: carereceiver) {
CarereceiverAvatarCell(carereceiver: carereceiver)
}
}

// ? Last item is Add profile button
self.addCarereceiverButton
}
.padding()
}
}
.padding()
.navigationTitle(String(l10n.CarereceiverPicker.title.characters))
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button {
self.isCarereceiverCreationPresented = true
} label: {
Text(l10n.CarereceiverPicker.addButtonLabel)
}
}
}
.sheet(isPresented: self.$isCarereceiverCreationPresented) {
CreateCarereceiverView(isPresented: self.$isCarereceiverCreationPresented) {}
}
.navigationDestination(for: Carereceiver.self) { carereceiver in
CarereceiverView(carereceiver: carereceiver)
}
}
}

Expand All @@ -48,29 +53,6 @@ struct CarereceiverPicker: View {

@State private var selected: String = ""
@State private var isCarereceiverCreationPresented: Bool = false

private var addCarereceiverButton: some View {
Button {
self.isCarereceiverCreationPresented = true
} label: {
VStack(spacing: 10) {
Circle()
.fill(Color(uiColor: .systemGray4))
.frame(maxWidth: 120)
.overlay {
Image(systemName: "plus")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
.foregroundStyle(.gray)
}

Text(l10n.CarereceiverPicker.addButtonLabel)
.font(.headline)
.foregroundStyle(.secondary)
}
}
}
}

// MARK: - l10n.CarereceiverPicker
Expand Down

0 comments on commit a8a010c

Please sign in to comment.