From 728a6c30000b4e5c34c3ca25f240d97e7dfbfd83 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Fri, 6 Feb 2026 08:22:59 -0500 Subject: [PATCH] feat: Adds CSV upload form to room view. --- Sources/Styleguide/SVG.swift | 5 ++ .../Views/Rooms/RoomsView.swift | 63 ++++++++++++++----- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Sources/Styleguide/SVG.swift b/Sources/Styleguide/SVG.swift index be0a04e..4c225ef 100644 --- a/Sources/Styleguide/SVG.swift +++ b/Sources/Styleguide/SVG.swift @@ -26,6 +26,7 @@ extension SVG { case doorClosed case email case fan + case filePlusCorner case key case mapPin case rulerDimensionLine @@ -94,6 +95,10 @@ extension SVG { return """ """ + case .filePlusCorner: + return """ + + """ case .key: return """ diff --git a/Sources/ViewController/Views/Rooms/RoomsView.swift b/Sources/ViewController/Views/Rooms/RoomsView.swift index 91fd4c8..b4b6d5b 100644 --- a/Sources/ViewController/Views/Rooms/RoomsView.swift +++ b/Sources/ViewController/Views/Rooms/RoomsView.swift @@ -7,7 +7,6 @@ import Styleguide struct RoomsView: HTML, Sendable { @Environment(ProjectViewValue.$projectID) var projectID - // let projectID: Project.ID let rooms: [Room] let sensibleHeatRatio: Double? @@ -25,7 +24,7 @@ struct RoomsView: HTML, Sendable { PageTitle { "Room Loads" } } - div(.class("flex justify-end grow")) { + div(.class("flex justify-end grow space-x-4")) { Tooltip("Set sensible heat ratio", position: .left) { button( .class( @@ -50,17 +49,6 @@ struct RoomsView: HTML, Sendable { } .attributes(.class("tooltip-open"), when: sensibleHeatRatio == nil) - Tooltip("Upload csv file", position: .left) { - form( - .hx.post(csvRoute), - .hx.target("body"), - .hx.swap(.outerHTML), - .custom(name: "enctype", value: "multipart/form-data") - ) { - input(.type(.file), .name("file"), .accept(".csv")) - SubmitButton() - } - } } div(.class("flex items-end space-x-4 font-bold")) { @@ -115,7 +103,17 @@ struct RoomsView: HTML, Sendable { } } th { - div(.class("flex justify-end me-2")) { + div(.class("flex justify-end me-2 space-x-4")) { + + Tooltip("Upload CSV", position: .left) { + button( + .class("btn btn-secondary"), + .showModal(id: UploadCSVForm.id) + ) { + SVG(.filePlusCorner) + } + } + Tooltip("Add Room") { PlusButton() .attributes( @@ -124,6 +122,7 @@ struct RoomsView: HTML, Sendable { ) .attributes(.class("tooltip-left")) } + } } } @@ -135,6 +134,7 @@ struct RoomsView: HTML, Sendable { } } RoomForm(dismiss: true, projectID: projectID, room: nil) + UploadCSVForm(dismiss: true) } } @@ -257,4 +257,39 @@ struct RoomsView: HTML, Sendable { } } } + + struct UploadCSVForm: HTML { + static let id = "uploadCSV" + + @Environment(ProjectViewValue.$projectID) var projectID + let dismiss: Bool + + private var route: String { + SiteRoute.router.path(for: .view(.project(.detail(projectID, .rooms(.index))))) + .appendingPath("csv") + } + + var body: some HTML { + ModalForm(id: Self.id, dismiss: dismiss) { + div(.class("pb-6 space-y-3")) { + h1(.class("text-3xl font-bold")) { "Upload CSV" } + p(.class("text-sm italic")) { + "Drag and drop, or click to upload" + } + } + form( + .hx.post(route), + .hx.target("body"), + .hx.swap(.outerHTML), + .custom(name: "enctype", value: "multipart/form-data") + ) { + input(.type(.file), .name("file"), .accept(".csv")) + + SubmitButton() + .attributes(.class("btn-block mt-6")) + } + } + } + + } }