Skip to content

Commit d30f888

Browse files
committed
Make BookingNotesView bindable
1 parent 1857228 commit d30f888

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
lines changed

WooCommerce/Classes/ViewModels/Booking Details/BookingDetailsViewModel+SectionContent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension BookingDetailsViewModel {
77
case attendance(AttendanceContent)
88
case payment(PaymentContent)
99
case customer(CustomerContent)
10-
case bookingNotes
10+
case bookingNotes(NotesContent)
1111
}
1212
}
1313

WooCommerce/Classes/ViewModels/Booking Details/BookingDetailsViewModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class BookingDetailsViewModel: ObservableObject {
1818
private let appointmentDetailsContent = AppointmentDetailsContent()
1919
private let attendanceContent = AttendanceContent()
2020
private let paymentContent = PaymentContent()
21+
private let notesContent = NotesContent()
2122

2223
// EntityListener: Update / Deletion Notifications.
2324
///
@@ -34,8 +35,6 @@ final class BookingDetailsViewModel: ObservableObject {
3435
booking.attendanceStatus
3536
}
3637

37-
var note: String { booking.note }
38-
3938
init(booking: Booking,
4039
stores: StoresManager = ServiceLocator.stores,
4140
storage: StorageManagerType = ServiceLocator.storageManager) {
@@ -74,7 +73,7 @@ private extension BookingDetailsViewModel {
7473
let bookingNotes = Section(
7574
header: .title(Localization.bookingNoteSectionHeaderTitle.uppercased()),
7675
footerText: Localization.bookingNoteSectionFooterText,
77-
content: .bookingNotes
76+
content: .bookingNotes(notesContent)
7877
)
7978

8079
sections = [
@@ -104,6 +103,7 @@ private extension BookingDetailsViewModel {
104103
attendanceContent.update(with: booking)
105104

106105
paymentContent.update(with: booking)
106+
notesContent.update(with: booking)
107107
}
108108

109109
func setupCustomerSectionVisibility() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Foundation
2+
import struct Networking.Booking
3+
4+
extension BookingDetailsViewModel {
5+
final class NotesContent: ObservableObject {
6+
@Published var value: String = ""
7+
8+
func update(with booking: Booking) {
9+
value = booking.note
10+
}
11+
}
12+
}

WooCommerce/Classes/ViewRelated/Bookings/Booking Details/BookingDetailsView.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ private extension BookingDetailsView {
159159
})
160160
case .payment(let content):
161161
paymentDetailsView(with: content)
162-
case .bookingNotes:
163-
bookingNotesView()
162+
case .bookingNotes(let content):
163+
BookingNotesRowView(content: content) { newNote in
164+
await viewModel.updateNote(to: newNote)
165+
}
164166
}
165167
}
166168

@@ -240,14 +242,6 @@ private extension BookingDetailsView {
240242
}
241243
.padding(.vertical)
242244
}
243-
244-
func bookingNotesView() -> some View {
245-
MultilineEditableTextRow(value: viewModel.note,
246-
placeholder: Localization.bookingNotesRowText,
247-
detailTitle: Localization.bookingNoteNavbarText) { newNote in
248-
return await viewModel.updateNote(to: newNote)
249-
}
250-
}
251245
}
252246

253247
extension BookingDetailsView {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import SwiftUI
2+
3+
struct BookingNotesRowView: View {
4+
@ObservedObject var content: BookingDetailsViewModel.NotesContent
5+
let onCommit: (String) async -> MultilineCommitResult
6+
7+
var body: some View {
8+
MultilineEditableTextRow(
9+
value: $content.value,
10+
placeholder: BookingDetailsView.Localization.bookingNotesRowText,
11+
detailTitle: BookingDetailsView.Localization.bookingNoteNavbarText,
12+
onCommit: onCommit
13+
)
14+
}
15+
}

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/MultilineEditableTextRow/MultilineEditableTextRow.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import SwiftUI
22

33
struct MultilineEditableTextRow: View {
4-
@State var value: String
4+
@Binding var value: String
55
let placeholder: String
66
let detailTitle: String?
77
let onCommit: (String) async -> MultilineCommitResult
88

9-
init(value: String,
9+
init(value: Binding<String>,
1010
placeholder: String,
1111
detailTitle: String? = nil,
1212
onCommit: @escaping (String) async -> MultilineCommitResult
1313
) {
14-
self._value = State(initialValue: value)
14+
self._value = value
1515
self.placeholder = placeholder
1616
self.detailTitle = detailTitle
1717
self.onCommit = onCommit
@@ -64,7 +64,7 @@ fileprivate extension MultilineEditableTextRow {
6464
@Previewable @State var text: String = ""
6565

6666
NavigationStack {
67-
MultilineEditableTextRow(value: text, placeholder: "Add note") { _ in
67+
MultilineEditableTextRow(value: $text, placeholder: "Add note") { _ in
6868
return .success
6969
}
7070
.padding(.horizontal, 16)

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,8 @@
13381338
57F2C6CD246DECC10074063B /* SummaryTableViewCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F2C6CC246DECC10074063B /* SummaryTableViewCellViewModelTests.swift */; };
13391339
57F42E40253768D600EA87F7 /* TitleAndEditableValueTableViewCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F42E3F253768D600EA87F7 /* TitleAndEditableValueTableViewCellViewModelTests.swift */; };
13401340
640DA3482E97DE4F00317FB2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640DA3472E97DE4F00317FB2 /* SceneDelegate.swift */; };
1341+
647C05FB2ED5D9E800E5FF3F /* NotesContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647C05FA2ED5D9E200E5FF3F /* NotesContent.swift */; };
1342+
647C05FD2ED5E1C000E5FF3F /* BookingNotesRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647C05FC2ED5E1C000E5FF3F /* BookingNotesRowView.swift */; };
13411343
6489DFFF2EA78E0D00D96802 /* MockProductDetailCoordinatorFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6489DFFE2EA78E0D00D96802 /* MockProductDetailCoordinatorFactory.swift */; };
13421344
6489E0012EA78E2D00D96802 /* MockProductDetailCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6489E0002EA78E2D00D96802 /* MockProductDetailCoordinator.swift */; };
13431345
64D355A52E99048E005F53F7 /* TestingSceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64D355A42E99048E005F53F7 /* TestingSceneDelegate.swift */; };
@@ -4232,6 +4234,8 @@
42324234
57F2C6CC246DECC10074063B /* SummaryTableViewCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryTableViewCellViewModelTests.swift; sourceTree = "<group>"; };
42334235
57F42E3F253768D600EA87F7 /* TitleAndEditableValueTableViewCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleAndEditableValueTableViewCellViewModelTests.swift; sourceTree = "<group>"; };
42344236
640DA3472E97DE4F00317FB2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
4237+
647C05FA2ED5D9E200E5FF3F /* NotesContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesContent.swift; sourceTree = "<group>"; };
4238+
647C05FC2ED5E1C000E5FF3F /* BookingNotesRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookingNotesRowView.swift; sourceTree = "<group>"; };
42354239
6489DFFE2EA78E0D00D96802 /* MockProductDetailCoordinatorFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockProductDetailCoordinatorFactory.swift; sourceTree = "<group>"; };
42364240
6489E0002EA78E2D00D96802 /* MockProductDetailCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockProductDetailCoordinator.swift; sourceTree = "<group>"; };
42374241
64D355A42E99048E005F53F7 /* TestingSceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingSceneDelegate.swift; sourceTree = "<group>"; };
@@ -7916,6 +7920,7 @@
79167920
2DAC251E2E829FF9008521AF /* Booking Details */ = {
79177921
isa = PBXGroup;
79187922
children = (
7923+
647C05FA2ED5D9E200E5FF3F /* NotesContent.swift */,
79197924
2D05E8122E8AADB2004111FD /* PaymentContent.swift */,
79207925
2D05E8102E8A98FE004111FD /* CustomerContent.swift */,
79217926
2D05E80E2E86BE4F004111FD /* AttendanceContent.swift */,
@@ -7941,6 +7946,7 @@
79417946
2DAC2C962E82A169008521AF /* Booking Details */ = {
79427947
isa = PBXGroup;
79437948
children = (
7949+
647C05FC2ED5E1C000E5FF3F /* BookingNotesRowView.swift */,
79447950
2D0555802E9693E1004111FD /* HeaderView.swift */,
79457951
2D052FB22E9408AF004111FD /* BookingDetailsView+RowTextStyle.swift */,
79467952
2D052FB32E9408AF004111FD /* CustomerDetailsView.swift */,
@@ -14232,6 +14238,7 @@
1423214238
EEBA02A52ADD606D001FE8E4 /* BlazeCampaignDashboardViewModel.swift in Sources */,
1423314239
77E53EB8250E6A4E003D385F /* ProductDownloadListViewController.swift in Sources */,
1423414240
26CE6F392B7E71AA008DB858 /* ConnectivityTool.swift in Sources */,
14241+
647C05FD2ED5E1C000E5FF3F /* BookingNotesRowView.swift in Sources */,
1423514242
020EF5EB2A8C7105009D2169 /* SiteSnapshotTracker.swift in Sources */,
1423614243
029106C02BE3349500C2248B /* OrderCustomerSectionViewModel.swift in Sources */,
1423714244
74460D4022289B7600D7316A /* Coordinator.swift in Sources */,
@@ -14664,6 +14671,7 @@
1466414671
26F94E2E267A96A000DB6CCF /* ProductAddOnViewModel.swift in Sources */,
1466514672
02A9BCD42737DE0D00159C79 /* JetpackBenefitsView.swift in Sources */,
1466614673
EE19058E2B5F747200617C53 /* BlazeAddPaymentMethodWebViewModel.swift in Sources */,
14674+
647C05FB2ED5D9E800E5FF3F /* NotesContent.swift in Sources */,
1466714675
20D5CB512AFCF856009A39C3 /* PaymentsRow.swift in Sources */,
1466814676
E10459C627BBC22E00C1DCBA /* CardPresentConfigurationLoader.swift in Sources */,
1466914677
B586906621A5F4B1001F1EFC /* UINavigationController+Woo.swift in Sources */,

0 commit comments

Comments
 (0)