File tree Expand file tree Collapse file tree 3 files changed +25
-24
lines changed
ViewModels/Booking Details
ViewRelated/Bookings/Booking Details Expand file tree Collapse file tree 3 files changed +25
-24
lines changed Original file line number Diff line number Diff line change @@ -15,17 +15,18 @@ struct BookingBadgeView: View {
1515 }
1616}
1717
18- extension BookingBadgeView {
19- init ( _ status : BookingAttendanceStatus ) {
20- self . init ( text : status . localizedTitle , color : status . badgeColor )
21- }
18+ protocol BookingBadgeable {
19+ var text : String { get }
20+ var badgeColor : Color { get }
21+ }
2222
23- init ( _ status: BookingStatus ) {
24- self . init ( text: status. localizedTitle, color: status. badgeColor)
23+ extension BookingBadgeView {
24+ init ( _ badgeable: BookingBadgeable ) {
25+ self . init ( text: badgeable. text, color: badgeable. badgeColor)
2526 }
2627}
2728
28- extension BookingAttendanceStatus {
29+ extension BookingAttendanceStatus : BookingBadgeable {
2930 var badgeColor : Color {
3031 switch self {
3132 case . noShow:
@@ -34,9 +35,13 @@ extension BookingAttendanceStatus {
3435 return BadgeColor . default
3536 }
3637 }
38+
39+ var text : String {
40+ self . localizedTitle
41+ }
3742}
3843
39- extension BookingStatus {
44+ extension BookingStatus : BookingBadgeable {
4045 var badgeColor : Color {
4146 switch self {
4247 case . unpaid:
@@ -45,6 +50,10 @@ extension BookingStatus {
4550 return BadgeColor . default
4651 }
4752 }
53+
54+ var text : String {
55+ self . localizedTitle
56+ }
4857}
4958
5059fileprivate enum BadgeColor {
Original file line number Diff line number Diff line change @@ -3,11 +3,14 @@ import struct Yosemite.Booking
33import struct Yosemite. BookingProductInfo
44import struct Yosemite. Customer
55import struct Yosemite. Address
6+ import enum Yosemite. BookingAttendanceStatus
7+ import enum Yosemite. BookingStatus
68
79extension BookingDetailsViewModel {
810 final class HeaderContent : ObservableObject {
911 @Published private( set) var bookingDate : String = " "
10- @Published private( set) var status : [ String ] = [ ]
12+ @Published private( set) var attendanceStatus : BookingAttendanceStatus = . unknown
13+ @Published private( set) var bookingStatus : BookingStatus = . unknown
1114 @Published private( set) var serviceAndCustomerLine : String = " "
1215
1316 func update( with booking: Booking ) {
@@ -17,11 +20,8 @@ extension BookingDetailsViewModel {
1720 timeZone: BookingListTab . utcTimeZone
1821 )
1922 serviceAndCustomerLine = booking. summaryText
20-
21- status = [
22- booking. attendanceStatus. localizedTitle,
23- booking. bookingStatus. localizedTitle
24- ]
23+ attendanceStatus = booking. attendanceStatus
24+ bookingStatus = booking. bookingStatus
2525 }
2626 }
2727}
Original file line number Diff line number Diff line change @@ -17,16 +17,8 @@ extension BookingDetailsView {
1717 . foregroundColor ( . secondary)
1818 }
1919 HStack {
20- ForEach ( content. status, id: \. self) { statusString in
21- Text ( statusString)
22- . font ( . caption2)
23- . padding ( . vertical, 4.5 )
24- . padding ( . horizontal, 8 )
25- . background (
26- BookingDetailsView . Layout. defaultBadgeColor
27- )
28- . cornerRadius ( 4 )
29- }
20+ BookingBadgeView ( content. attendanceStatus)
21+ BookingBadgeView ( content. bookingStatus)
3022 }
3123 . padding ( . top, Layout . headerBadgesAdditionalTopPadding)
3224 }
You can’t perform that action at this time.
0 commit comments