Skip to content

Commit

Permalink
Merge pull request #42 from DatepollSystems/feature/shared-update
Browse files Browse the repository at this point in the history
TableGroup ProductGroup coloring, shared update
  • Loading branch information
kaulex99 authored Jul 10, 2024
2 parents a1e5836 + 4ceaa19 commit 06765d6
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0x00",
"green" : "0x22",
"red" : "0x9B"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0x3C",
"green" : "0x34",
"red" : "0xFF"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 3 additions & 3 deletions WaiterRobot/Ui/Billing/BillingScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct BillingScreen: View {
let billItems = Array(viewModel.state.billItemsArray)

content(billItems: billItems)
.navigationTitle(localize.billing.title(value0: table.number.description, value1: table.groupName))
.navigationTitle(localize.billing.title(value0: table.groupName, value1: table.number.description))
.navigationBarTitleDisplayMode(.inline)
.customBackNavigation(
title: localize.dialog.cancel(),
Expand Down Expand Up @@ -63,7 +63,6 @@ struct BillingScreen: View {
}
}
}

// TODO: make only half screen when ios 15 is dropped
.sheet(isPresented: $showPayDialog) {
PayDialog(viewModel: viewModel)
Expand All @@ -76,7 +75,7 @@ struct BillingScreen: View {
VStack {
List {
if billItems.isEmpty {
Text(localize.billing.noOpenBill(value0: table.number.description, value1: table.groupName))
Text(localize.billing.noOpenBill(value0: table.groupName, value1: table.number.description))
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding()
Expand Down Expand Up @@ -124,6 +123,7 @@ struct BillingScreen: View {
.font(.system(.title))
.padding()
.tint(.white)
.offset(x: -3)
}
.background(.blue)
.mask(Circle())
Expand Down
2 changes: 1 addition & 1 deletion WaiterRobot/Ui/Order/OrderScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct OrderScreen: View {
currentOder(resource.data)
}
}
.navigationTitle(localize.order.title(value0: table.number.description, value1: table.groupName))
.navigationTitle(localize.order.title(value0: table.groupName, value1: table.number.description))
.navigationBarTitleDisplayMode(.large)
.navigationBarBackButtonHidden()
.confirmationDialog(
Expand Down
85 changes: 64 additions & 21 deletions WaiterRobot/Ui/Order/ProductListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import SwiftUI

struct ProductListItem: View {
let product: Product
let backgroundColor: Color?
let onClick: () -> Void

private let allergens: String

init(product: Product, onClick: @escaping () -> Void) {
init(
product: Product,
backgroundColor: Color?,
onClick: @escaping () -> Void
) {
self.product = product
self.backgroundColor = backgroundColor
self.onClick = onClick

var allergens = ""
Expand All @@ -23,29 +29,42 @@ struct ProductListItem: View {
}
}

var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(product.soldOut ? Color.gray.opacity(0.1) : Color(.systemBackground))
.shadow(radius: 2)
var foregroundColor: Color {
if product.soldOut {
return .blackWhite
}

if let backgroundColor {
return backgroundColor.getContentColor(lightColorScheme: .black, darkColorScheme: .white)
} else {
return Color.blackWhite
}
}

Button {
onClick()
} label: {
VStack {
Text(product.name)
.strikethrough(product.soldOut)
if !product.allergens.isEmpty {
Text(allergens)
.foregroundColor(.gray)
}
Text(product.price.description())
var body: some View {
Button {
onClick()
} label: {
VStack {
Text(product.name)
.strikethrough(product.soldOut)
.foregroundStyle(foregroundColor)
if !product.allergens.isEmpty {
Text(allergens)
.foregroundStyle(foregroundColor)
.opacity(0.6)
}
.foregroundColor(.blackWhite)
.frame(maxWidth: .infinity)
.padding(5)
Text(product.price.description())
}
.disabled(product.soldOut)
.foregroundStyle(foregroundColor)
.frame(maxWidth: .infinity)
.padding(5)
}
.disabled(product.soldOut)
.background {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(product.soldOut ? Color.gray.opacity(0.1) : backgroundColor ?? Color(.systemBackground))
.shadow(radius: 2)
}
}
}
Expand All @@ -66,6 +85,30 @@ struct ProductListItem: View {
],
position: 1
),
backgroundColor: .yellow,
onClick: {}
)
.frame(maxWidth: 100, maxHeight: 100)
}

#Preview {
ProductListItem(
product: Product(
id: 2,
name: "Wine",
price: Money(cents: 290),
soldOut: false,
allergens: [
Allergen(id: 1, name: "Egg", shortName: "E"),
Allergen(id: 2, name: "Egg2", shortName: "A"),
Allergen(id: 3, name: "Egg3", shortName: "B"),
Allergen(id: 4, name: "Egg4", shortName: "C"),
Allergen(id: 5, name: "Egg5", shortName: "D"),
],
position: 1
),
backgroundColor: .yellow,
onClick: {}
)
.frame(maxWidth: 100, maxHeight: 100)
}
1 change: 1 addition & 0 deletions WaiterRobot/Ui/Order/Search/ProductSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct ProductSearch: View {
LazyVGrid(columns: layout, spacing: 0) {
ProductSearchGroupList(
products: groupWithProducts.products,
backgroundColor: Color(hex: groupWithProducts.color),
onProductClick: {
viewModel.actual.addItem(product: $0, amount: 1)
dismiss()
Expand Down
2 changes: 2 additions & 0 deletions WaiterRobot/Ui/Order/Search/ProductSearchAllTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct ProductSearchAllTab: View {
Section {
ProductSearchGroupList(
products: productGroup.products,
backgroundColor: Color(hex: productGroup.color),
onProductClick: onProductClick
)
} header: {
Expand All @@ -38,6 +39,7 @@ struct ProductSearchAllTab: View {
id: 1,
name: "Test Group 1",
position: 1,
color: "",
products: [
Product(
id: 1,
Expand Down
4 changes: 3 additions & 1 deletion WaiterRobot/Ui/Order/Search/ProductSearchGroupList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import SwiftUI

struct ProductSearchGroupList: View {
let products: [Product]
let backgroundColor: Color?
let onProductClick: (Product) -> Void

var body: some View {
ForEach(products, id: \.id) { product in
ProductListItem(product: product) {
ProductListItem(product: product, backgroundColor: backgroundColor) {
onProductClick(product)
}
.foregroundColor(.blackWhite)
Expand All @@ -29,6 +30,7 @@ struct ProductSearchGroupList: View {
position: 1
),
],
backgroundColor: .yellow,
onProductClick: { _ in }
)
}
Expand Down
4 changes: 2 additions & 2 deletions WaiterRobot/Ui/TableDetail/TableDetailScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct TableDetailScreen: View {

var body: some View {
content()
.navigationTitle(localize.tableDetail.title(value0: table.number.description, value1: table.groupName))
.navigationTitle(localize.tableDetail.title(value0: table.groupName, value1: table.number.description))
.withViewModel(viewModel, navigator)
}

Expand Down Expand Up @@ -45,7 +45,7 @@ struct TableDetailScreen: View {
if orderedItems.isEmpty {
Spacer()

Text(localize.tableDetail.noOrder(value0: table.number.description, value1: table.groupName))
Text(localize.tableDetail.noOrder(value0: table.groupName, value1: table.number.description))
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding()
Expand Down
25 changes: 17 additions & 8 deletions WaiterRobot/Ui/TableList/TableGroupSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct TableGroupSection: View {
TableView(
text: table.number.description,
hasOrders: table.hasOrders,
backgroundColor: Color(hex: tableGroup.color),
onClick: {
onTableClick(table)
}
Expand All @@ -19,19 +20,27 @@ struct TableGroupSection: View {
}
} header: {
HStack {
Text(tableGroup.name)
.font(.title2)
.foregroundStyle(.white)
.padding(6)
.background {
RoundedRectangle(cornerRadius: 8.0)
.foregroundStyle(Color(.main))
}
if let background = Color(hex: tableGroup.color) {
title(backgroundColor: background)
} else {
title(backgroundColor: Color(.main))
}

Spacer()
}
}
}

private func title(backgroundColor: Color) -> some View {
Text(tableGroup.name)
.font(.title2)
.foregroundStyle(backgroundColor.getContentColor(lightColorScheme: .black, darkColorScheme: .white))
.padding(6)
.background {
RoundedRectangle(cornerRadius: 8.0)
.foregroundStyle(backgroundColor)
}
}
}

#Preview {
Expand Down
26 changes: 19 additions & 7 deletions WaiterRobot/Ui/TableList/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ import SwiftUI
struct TableView: View {
let text: String
let hasOrders: Bool
let backgroundColor: Color?
let onClick: () -> Void

@Environment(\.colorScheme)
var colorScheme

var body: some View {
Button(action: onClick) {
ZStack {
RoundedRectangle(cornerRadius: 20)
.stroke(.blackWhite, lineWidth: 5)

Text(text)
.font(.title)
.frame(maxWidth: .infinity, maxHeight: .infinity)

if hasOrders {
VStack(alignment: .trailing) {
HStack {
Spacer()

Circle()
.foregroundColor(.accentColor)
.foregroundColor(backgroundColor?.getContentColor(lightColorScheme: Color(.darkRed), darkColorScheme: Color(.lightRed)))
.frame(width: 12)
}

Spacer()
}
.padding(.top, 10)
Expand All @@ -31,16 +34,25 @@ struct TableView: View {
}
}
.aspectRatio(1.0, contentMode: .fit)
.foregroundColor(.blackWhite)
.background {
if let backgroundColor {
RoundedRectangle(cornerRadius: 20)
.foregroundColor(backgroundColor)
} else {
RoundedRectangle(cornerRadius: 20)
.foregroundColor(.gray.opacity(0.3))
}
}
.foregroundStyle(backgroundColor?.getContentColor(lightColorScheme: .black, darkColorScheme: .white) ?? .blackWhite)
}
}

#Preview {
VStack {
TableView(text: "1", hasOrders: false, onClick: {})
TableView(text: "1", hasOrders: false, backgroundColor: .green) {}
.frame(maxWidth: 100)

TableView(text: "2", hasOrders: true, onClick: {})
TableView(text: "2", hasOrders: true, backgroundColor: nil) {}
.frame(maxWidth: 100)
}
}
Loading

0 comments on commit 06765d6

Please sign in to comment.