Skip to content

Commit

Permalink
Fixed TableDetails and OrderScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
kaulex99 committed Feb 25, 2024
1 parent f065ad8 commit 5de9b59
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 88 deletions.
5 changes: 4 additions & 1 deletion WaiterRobot/Ui/Billing/BillingScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ struct BillingScreen: View {
content()
.navigationTitle(localize.billing.title(value0: table.number.description, value1: table.groupName))
.navigationBarTitleDisplayMode(.inline)
// .customBackNavigation(title: localize.dialog.cancel(), icon: nil, action: { viewModel.actual.goBack() }) // TODO: whatever?
.customBackNavigation(title: localize.dialog.cancel(), icon: nil) {
viewModel.actual.abortBill()
}
// TODO: whatever?
// .confirmationDialog(localize.billing.notSent.title(), isPresented: Binding.constant(viewModel.state.showConfirmationDialog), titleVisibility: .visible) {
// Button(localize.dialog.closeAnyway(), role: .destructive, action: { viewModel.actual.abortBill() })
// Button(localize.dialog.cancel(), role: .cancel, action: { viewModel.actual.keepBill() })
Expand Down
24 changes: 24 additions & 0 deletions WaiterRobot/Ui/Core/IfCondition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// IfCondition.swift
// WaiterRobot
//
// Created by Alexander Kauer on 25.02.24.
//

import Foundation
import SwiftUI

extension View {
/// Applies the given transform if the given condition evaluates to `true`.
/// - Parameters:
/// - condition: The condition to evaluate.
/// - transform: The transform to apply to the source `View`.
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`.
@ViewBuilder func ifCondition(_ condition: Bool, transform: (Self) -> some View) -> some View {
if condition {
transform(self)
} else {
self
}
}
}
32 changes: 32 additions & 0 deletions WaiterRobot/Ui/Core/WRBorderedProminentButtonStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// WRBorderedProminentButtonStyle.swift
// WaiterRobot
//
// Created by Alexander Kauer on 25.02.24.
//

import SwiftUI

struct WRBorderedProminentButtonStyle: ButtonStyle {
@Environment(\.isEnabled) private var isEnabled: Bool

func makeBody(configuration: Configuration) -> some View {
configuration.label
.foregroundStyle(isEnabled ? .white : .white.opacity(0.8))
.background(
RoundedRectangle(cornerRadius: 10)
.ifCondition(isEnabled) { view in
view.foregroundStyle(configuration.isPressed ? .main.opacity(0.6) : .main)
}
.ifCondition(!isEnabled) { view in
view.foregroundStyle(.gray)
}
)
}
}

extension ButtonStyle where Self == WRBorderedProminentButtonStyle {
static var wrBorderedProminent: WRBorderedProminentButtonStyle {
WRBorderedProminentButtonStyle()
}
}
62 changes: 62 additions & 0 deletions WaiterRobot/Ui/Core/WrToolbar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// WrToolbar.swift
// WaiterRobot
//
// Created by Alexander Kauer on 25.02.24.
//

import SwiftUI

extension View {
func wrBottomBar<ToolbarView: View>(@ViewBuilder toolbar: @escaping () -> ToolbarView) -> some View {
modifier(WrToolbarModifier<ToolbarView>(toolbar: toolbar))
}
}

struct WrToolbarModifier<ToolbarView: View>: ViewModifier {
@ViewBuilder
let toolbar: ToolbarView

func body(content: Content) -> some View {
VStack(spacing: 0) {
content

VStack {
Divider()

HStack {
toolbar
}
.frame(maxWidth: .infinity)
.padding(.horizontal)
.padding(.top, 4)
}
}
}
}

#Preview {
Text("hello")
.wrBottomBar {
Button {} label: {
Image(systemName: "creditcard")
.padding(12)
}
.buttonStyle(.wrBorderedProminent)

Button {} label: {
Image(systemName: "plus")
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)

Button {} label: {
Image(systemName: "plus")
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)
.disabled(true)
}
}
158 changes: 110 additions & 48 deletions WaiterRobot/Ui/Order/OrderScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,126 @@ struct OrderScreen: View {
self.table = table
_viewModel = StateObject(wrappedValue: ObservableOrderViewModel(table: table, initialItemId: initialItemId))
showProductSearch = initialItemId == nil ? true : false

UIToolbar.appearance().barTintColor = UIColor.systemBackground // Background color
UIToolbar.appearance().tintColor = UIColor.blue // Tint color of buttonss
}

var body: some View {
ScreenContainer(viewModel.state) {
ZStack {
// VStack {
// if viewModel.state.currentOrder.isEmpty {
// Text(localize.order.addProduct())
// .multilineTextAlignment(.center)
// .frame(maxWidth: .infinity)
// .padding()
// } else {
// List {
// ForEach(viewModel.state.currentOrder, id: \.product.id) { orderItem in
// OrderListItem(
// name: orderItem.product.name,
// amount: orderItem.amount,
// note: orderItem.note,
// addOne: { viewModel.actual.addItem(product: orderItem.product, amount: 1) },
// removeOne: { viewModel.actual.addItem(product: orderItem.product, amount: -1) },
// removeAll: { viewModel.actual.removeAllOfProduct(productId: orderItem.product.id) },
// onSaveNote: { note in
// viewModel.actual.addItemNote(item: orderItem, note: note)
// }
// )
// }
// }
// }
// }
//
// EmbeddedFloatingActionButton(icon: "plus") {
// showProductSearch = true
// }
VStack {
switch onEnum(of: viewModel.state.currentOrder) {
case .loading:
ProgressView()

case let .error(error):
Text(error.userMessage)

case let .success(resource):
if let data = resource.data {
currentOder(data)
}
}
}
// .navigationTitle(localize.order.title(value0: table.number.description, value1: table.groupName))
// .navigationBarTitleDisplayMode(.large)
// .navigationBarBackButtonHidden()
// .toolbar {
// ToolbarItem(placement: .navigationBarTrailing) {
// Button {
// viewModel.actual.sendOrder()
// } label: {
// Image(systemName: "paperplane.fill")
// }
// .disabled(viewModel.state.currentOrder.isEmpty || viewModel.state.viewState != ViewState.Idle.shared)
// }
// }
// .customBackNavigation(title: localize.dialog.cancel(), icon: "chevron.backward", action: { viewModel.actual.goBack() })
.navigationTitle(localize.order.title(value0: table.number.description, value1: table.groupName))
.navigationBarTitleDisplayMode(.large)
.navigationBarBackButtonHidden()
// TODO: check if confirmation was dropped
.customBackNavigation(title: localize.dialog.cancel(), icon: "chevron.backward", action: { viewModel.actual.abortOrder() })
// .confirmationDialog(localize.order.notSent.title(), isPresented: Binding.constant(viewModel.state.showConfirmationDialog), titleVisibility: .visible) {
// Button(localize.dialog.closeAnyway(), role: .destructive, action: { viewModel.actual.abortOrder() })
// Button(localize.order.keepOrder(), role: .cancel, action: { viewModel.actual.keepOrder() })
// } message: {
// Text(localize.order.notSent.desc())
// }
// .sheet(isPresented: $showProductSearch) {
// ProductSearch(viewModel: viewModel)
// }
// .handleSideEffects(of: viewModel, navigator)
.sheet(isPresented: $showProductSearch) {
ProductSearch(viewModel: viewModel)
}
.handleSideEffects(of: viewModel, navigator)
}

@ViewBuilder
private func currentOder(
_ currentOrderArray: KotlinArray<OrderItem>
) -> some View {
let currentOrder = Array(currentOrderArray)

VStack(spacing: 0) {
if currentOrder.isEmpty {
Spacer()

Text(localize.order.addProduct())
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding()

Spacer()
} else {
List {
ForEach(currentOrder, id: \.product.id) { orderItem in
OrderListItem(
name: orderItem.product.name,
amount: orderItem.amount,
note: orderItem.note,
addOne: { viewModel.actual.addItem(product: orderItem.product, amount: 1) },
removeOne: { viewModel.actual.addItem(product: orderItem.product, amount: -1) },
removeAll: { viewModel.actual.removeAllOfProduct(productId: orderItem.product.id) },
onSaveNote: { note in
viewModel.actual.addItemNote(item: orderItem, note: note)
}
)
}
}
}
}
.wrBottomBar {
Button {
viewModel.actual.sendOrder()
} label: {
Image(systemName: "paperplane.fill")
.imageScale(.small)
.padding(10)
}
.buttonStyle(.wrBorderedProminent)
.disabled(currentOrder.isEmpty)

Spacer()

Button {
showProductSearch = true
} label: {
Image(systemName: "plus")
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)
}

// VStack {
// Divider()
//
// HStack {
// Button {
// viewModel.actual.sendOrder()
// } label: {
// Image(systemName: "paperplane.fill")
// .imageScale(.small)
// .padding(10)
// }
// .buttonStyle(.wrBorderedProminent)
// .disabled(currentOrder.isEmpty)
//
// Spacer()
//
// Button {
// showProductSearch = true
// } label: {
// Image(systemName: "plus")
// .imageScale(.large)
// .padding()
// }
// .buttonStyle(.wrBorderedProminent)
// }
//
// }
}
}
Loading

0 comments on commit 5de9b59

Please sign in to comment.