Skip to content

Commit 68f9ce9

Browse files
committed
Minor improvements
- better detail text for products - preselect first product on macOS too
1 parent f79877d commit 68f9ce9

File tree

5 files changed

+63
-31
lines changed

5 files changed

+63
-31
lines changed

AppLogic/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
.package(url: "https://github.com/Lighter-swift/Lighter.git",
1818
from: "1.0.24"),
1919
.package(url: "https://github.com/Lighter-swift/NorthwindSQLite.swift.git",
20-
from: "1.0.10"),
20+
from: "1.0.12"),
2121

2222
.package(url: "https://github.com/Macro-swift/MacroExpress.git",
2323
from: "1.0.2"),

LighterExamples.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
E87B412228A3DC6500576D8A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
9292
E87B412428A3DC6500576D8A /* Bodies.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Bodies.entitlements; sourceTree = "<group>"; };
9393
E87B412628A3DC6500576D8A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
94-
E87B412C28A3DCAD00576D8A /* BodiesApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BodiesApp.swift; sourceTree = "<group>"; };
95-
E87B412D28A3DCAD00576D8A /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
94+
E87B412C28A3DCAD00576D8A /* BodiesApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = BodiesApp.swift; sourceTree = "<group>"; };
95+
E87B412D28A3DCAD00576D8A /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
9696
E87D45FE28A3C341008E04EA /* NavViewMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavViewMain.swift; sourceTree = "<group>"; };
9797
E8AF70C928A3DDE9008444B2 /* BodiesDB-001.sql */ = {isa = PBXFileReference; lastKnownFileType = text; path = "BodiesDB-001.sql"; sourceTree = "<group>"; };
9898
/* End PBXFileReference section */
@@ -138,7 +138,7 @@
138138
E8224F8C28A005CF00246A1F /* Products */,
139139
E8224FBC28A0066800246A1F /* Frameworks */,
140140
);
141-
indentWidth = 4;
141+
indentWidth = 2;
142142
sourceTree = "<group>";
143143
};
144144
E8224F8C28A005CF00246A1F /* Products */ = {

Sources/NorthwindSwiftUI/MainView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct MainView: View {
4545
case .products:
4646
ProductsList(products: $products,
4747
selectedProduct: $selectedProductID)
48+
#if os(macOS)
49+
.frame(minWidth: 274) // otherwise overlaps on macOS 13
50+
#endif
4851

4952
case .none:
5053
Text("No section is selected")

Sources/NorthwindSwiftUI/ProductCell.swift

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,57 @@ struct ProductCell: View {
1818
VStack(alignment: .leading) {
1919
Text(verbatim: product.productName)
2020
.font(.headline)
21-
22-
HStack(spacing: 0) {
23-
Text(product.unitPrice ?? 0, format: .currency(code: "USD"))
24-
if unitsInStock > 0 {
25-
Text(", \(unitsInStock) in stock")
26-
}
27-
else if product.discontinued != "0" {
28-
Text(", ") +
29-
Text("discontinued").foregroundColor(.red)
30-
}
31-
else {
32-
Text(", ") +
33-
Text("out of stock.").foregroundColor(.red)
34-
if let ordered = product.unitsOnOrder, ordered > 0 {
35-
Text(", ordered \(ordered)")
36-
}
37-
}
38-
}
39-
40-
if unitsInStock > 0 && product.discontinued != "0" {
41-
Text("Discontinued")
42-
.foregroundColor(.red)
43-
}
21+
22+
detailText
4423
}
4524
},
4625
icon: { Image(systemName: "p.circle") }
4726
)
4827
}
28+
29+
var detailText : Text {
30+
var text = Text(product.unitPrice ?? 0, format: .currency(code: "USD"))
31+
32+
if unitsInStock > 0 {
33+
text = text + Text(", \(unitsInStock) in stock")
34+
}
35+
else {
36+
text = text + Text(", ")
37+
text = text + Text("out of stock").foregroundColor(.red)
38+
if let ordered = product.unitsOnOrder, ordered > 0 {
39+
text = text + Text(", ordered \(ordered)")
40+
}
41+
}
42+
43+
if product.discontinued != "0" {
44+
text = text + Text(", ")
45+
text = text + Text("discontinued").foregroundColor(.red)
46+
}
47+
return text
48+
}
49+
50+
@ViewBuilder var productDetails : some View {
51+
HStack(spacing: 0) {
52+
Text(product.unitPrice ?? 0, format: .currency(code: "USD"))
53+
54+
if unitsInStock > 0 {
55+
Text(", \(unitsInStock) in stock")
56+
if product.discontinued != "0" {
57+
Text(", ") +
58+
Text("discontinued").foregroundColor(.red)
59+
}
60+
}
61+
else if product.discontinued != "0" {
62+
Text(", ") +
63+
Text("discontinued").foregroundColor(.red)
64+
}
65+
else {
66+
Text(", ") +
67+
Text("out of stock").foregroundColor(.red)
68+
if let ordered = product.unitsOnOrder, ordered > 0 {
69+
Text(", ordered \(ordered)")
70+
}
71+
}
72+
}
73+
}
4974
}

Sources/NorthwindSwiftUI/ProductsList.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ struct ProductsList: View {
3737
)
3838
}
3939

40-
#if !os(macOS)
41-
if horizontalSizeClass != .compact {
42-
// Pre-select the first match if none is selected
40+
// Pre-select the first match if none is selected.
41+
#if os(macOS)
4342
if selectedProduct == nil, let product = products.first {
4443
selectedProduct = product.id
4544
}
46-
}
45+
#else
46+
if horizontalSizeClass != .compact { // this waits for the tap
47+
if selectedProduct == nil, let product = products.first {
48+
selectedProduct = product.id
49+
}
50+
}
4751
#endif
4852
}
4953
catch { // really, do proper error handling :-)

0 commit comments

Comments
 (0)