Skip to content

Commit

Permalink
Merge branch 'develop' into feature/restructure
Browse files Browse the repository at this point in the history
# Conflicts:
#	WaiterRobot/Features/TableList/TableGroupSection.swift
#	WaiterRobot/Features/TableList/TableView.swift
  • Loading branch information
kaulex99 committed Aug 10, 2024
2 parents 49a1722 + 214ba79 commit cd8e505
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 45 deletions.
6 changes: 3 additions & 3 deletions WaiterRobot/Features/Billing/BillingScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 @@ -64,7 +64,6 @@ struct BillingScreen: View {
}
}
}

// TODO: make only half screen when ios 15 is dropped
.sheet(isPresented: $showPayDialog) {
PayDialog(viewModel: viewModel)
Expand All @@ -77,7 +76,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 @@ -125,6 +124,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/Features/Order/OrderScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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/Features/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/Features/Order/Search/ProductSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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/Features/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
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/Features/TableDetail/TableDetailScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 @@ -46,7 +46,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/Features/TableList/TableGroupSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct TableGroupSection: View {
TableView(
text: table.number.description,
hasOrders: table.hasOrders,
backgroundColor: Color(hex: tableGroup.color),
onClick: {
onTableClick(table)
}
Expand All @@ -21,21 +22,29 @@ struct TableGroupSection: View {
}
} header: {
HStack {
Text(tableGroup.name)
.font(.title2)
.foregroundStyle(.white)
.padding(6)
.background {
RoundedRectangle(cornerRadius: 8.0)
.foregroundStyle(Color.accent)
}
if let background = Color(hex: tableGroup.color) {
title(backgroundColor: background)
} else {
title(backgroundColor: .gray.opacity(0.3))
}

Spacer()
}
.padding(.vertical, 4)
.background(Color.whiteBlack)
}
}

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/Features/TableList/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,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(Color.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 @@ -32,16 +35,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)
}
}
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
}
}
Loading

0 comments on commit cd8e505

Please sign in to comment.