fix: Search button would stay on top of sidepanel when it was open.

This commit is contained in:
2025-01-18 09:05:07 -05:00
parent d8328314ed
commit 9efd920456
7 changed files with 62 additions and 166 deletions

View File

@@ -1,9 +1,12 @@
import Dependencies
import Elementary
import ElementaryHTMX
import SharedModels
struct PurchaseOrderForm: HTML {
@Dependency(\.dateFormatter) var dateFormatter
let purchaseOrder: PurchaseOrder?
let shouldShow: Bool
@@ -98,6 +101,17 @@ struct PurchaseOrderForm: HTML {
)
}
}
if let purchaseOrder, let createdAt = purchaseOrder.createdAt {
div(.class("row")) {
label(.class("label col-2")) { "Created:" }
h3(.class("col-2")) { dateFormatter.string(from: createdAt) }
if let updatedAt = purchaseOrder.updatedAt {
div(.class("col-1")) {}
label(.class("label col-2")) { "Updated:" }
h3(.class("col-2")) { dateFormatter.string(from: updatedAt) }
}
}
}
div(.class("btn-row")) {
button(.class("btn-primary"), .type(.submit)) { buttonLabel }
if purchaseOrder != nil {

View File

@@ -59,8 +59,9 @@ struct PurchaseOrderTable: HTML {
div(.class("btn-row")) {
if context != .search {
button(
.id("btn-search"),
.class("btn-primary"), .style("position: absolute; top: 80px; right: 20px;"),
.hx.get(route: .purchaseOrders(.search(.context(.employee)))),
.hx.get(route: .purchaseOrders(.search(.context(.employee, table: true)))),
.hx.target(.body),
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
.hx.pushURL(true)

View File

@@ -3,7 +3,38 @@ import ElementaryHTMX
import Fluent
import SharedModels
enum RouteContainer {
extension HTMLAttribute.hx {
static func get(route: RouteKey) -> HTMLAttribute {
get(route.url)
}
static func post(route: RouteKey) -> HTMLAttribute {
post(route.url)
}
static func put(route: RouteKey) -> HTMLAttribute {
put(route.url)
}
static func delete(route: RouteKey) -> HTMLAttribute {
delete(route.url)
}
}
extension HTMLAttribute.hx {
static func target(_ target: HXTarget) -> HTMLAttribute {
Self.target(target.selector)
}
}
extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global {
static func id(_ target: HXTarget) -> Self {
id(target.id)
}
}
enum RouteKey {
case employees(EmployeeRoute? = nil)
case purchaseOrders(PurchaseOrderRoute? = nil)
case users(UserRoute? = nil)
@@ -59,12 +90,14 @@ enum RouteContainer {
}
enum SearchQuery {
case context(PurchaseOrderSearchContext)
case context(PurchaseOrderSearchContext, table: Bool? = nil)
var query: String {
switch self {
case let .context(context):
return "context=\(context.rawValue)"
case let .context(context, table):
let query = "context=\(context.rawValue)"
guard let table else { return query }
return "\(query)&table=\(table)"
}
}
}
@@ -84,29 +117,6 @@ enum RouteContainer {
}
extension HTMLAttribute.hx {
static func get(route: RouteContainer) -> HTMLAttribute {
get(route.url)
}
static func post(route: RouteContainer) -> HTMLAttribute {
post(route.url)
}
static func put(route: RouteContainer) -> HTMLAttribute {
put(route.url)
}
static func delete(route: RouteContainer) -> HTMLAttribute {
delete(route.url)
}
}
enum RouteKey: String {
case purchaseOrders = "purchase-orders"
}
enum HXTarget {
case body
case employee(EmployeeKey)
@@ -185,19 +195,6 @@ enum HXTarget {
}
}
extension HTMLAttribute.hx {
static func target(_ target: HXTarget) -> HTMLAttribute {
Self.target(target.selector)
}
}
extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global {
static func id(_ target: HXTarget) -> Self {
id(target.id)
}
}
enum ViewRoute: String {
case employees