Skip to content

Commit

Permalink
Update Food List UI
Browse files Browse the repository at this point in the history
  • Loading branch information
vykut committed Dec 8, 2023
1 parent 66a24b9 commit 8c282f8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
7 changes: 1 addition & 6 deletions FoodSpec/Clients/SpotlightClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ extension SpotlightClient: DependencyKey {
let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
attributeSet.displayName = food.name.capitalized
attributeSet.title = "\(food.name.capitalized) nutritional values"
attributeSet.contentDescription = """
E: \(food.energy.formatted(width: .narrow)) | \
P: \(food.protein.formatted(width: .narrow)) | \
C: \(food.carbohydrates.formatted(width: .narrow)) | \
F: \(food.fatTotal.formatted(width: .narrow))
"""
attributeSet.contentDescription = food.nutritionalSummary
let searchableItem = CSSearchableItem(
uniqueIdentifier: food.name,
domainIdentifier: "foods",
Expand Down
10 changes: 10 additions & 0 deletions FoodSpec/Food List/FoodList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct FoodList: View {
.onDelete(perform: deleteItems)
} header: {
Text("Recent Searches")
} footer: {
Text("Values per \(Quantity(grams: 100).formatted(width: .wide))")
.font(.footnote)
}
}

Expand Down Expand Up @@ -134,6 +137,13 @@ struct FoodList: View {
initialState: FoodListReducer.State(),
reducer: {
FoodListReducer()
.transformDependency(\.databaseClient) {
$0.observeFoods = { _, _ in
.init {
$0.yield([.preview, .preview, .preview])
}
}
}
._printChanges()
}
)
Expand Down
7 changes: 1 addition & 6 deletions FoodSpec/Food List/FoodListRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ struct FoodListRow: View {
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text(food.name.capitalized)
HStack {
Text(food.energy.formatted(width: .narrow))
Text("P: \(food.protein.formatted(width: .narrow))")
Text("C: \(food.carbohydrates.formatted(width: .narrow))")
Text("F: \(food.fatTotal.formatted(width: .narrow))")
}
Text(food.nutritionalSummary)
.font(.footnote)
.foregroundStyle(.secondary)
}
Expand Down
9 changes: 9 additions & 0 deletions FoodSpec/Model/Food/Food.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ struct Food: Codable, Hashable {
var carbohydrates: Quantity
var fiber: Quantity
var sugar: Quantity

var nutritionalSummary: String {
"""
\(energy.formatted(width: .narrow)) | \
P: \(protein.formatted(width: .narrow)) | \
C: \(carbohydrates.formatted(width: .narrow)) | \
F: \(fatTotal.formatted(width: .narrow))
"""
}
}

extension Food: FetchableRecord, MutablePersistableRecord {
Expand Down

0 comments on commit 8c282f8

Please sign in to comment.