summaryrefslogtreecommitdiff
path: root/src/chef/pages/home.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef/pages/home.clj')
-rw-r--r--src/chef/pages/home.clj66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/chef/pages/home.clj b/src/chef/pages/home.clj
index 748c60c..9bc82fb 100644
--- a/src/chef/pages/home.clj
+++ b/src/chef/pages/home.clj
@@ -1,33 +1,51 @@
(ns chef.pages.home
- (:require [hiccup2.core :as html]
+ (:require [chef.database :as cdb]
+ [hiccup2.core :as html]
+ [honey.sql :as sql]
+ [next.jdbc :as jdbc]
[ring.util.response :as ruresp]
- [chef.utils :as cutils]))
+ [chef.utils :as cutils]
-(defn- render []
+ [chef.components.search :as ccsearch]))
+
+(defn- render [req]
(cutils/gen-page "chef"
- [:div {:style {:text-align :center}}
- [:h1 "chef"]
- [:h2 "Finde das perfekte Gericht für dich!"]
- [:b "Welchen Gang suchst du?"]
- ;; TODO: Dummy data; replace with data from db
- [:div
- [:button {:style {:margin-bottom "1em"}} "Vorspeise"]
- [:br]
- [:button {:style {:margin-bottom "1em"}} "Hauptgang"]
- [:br]
- [:button {:style {:margin-bottom "1em"}} "Nachtisch"]
- [:br]]
- [:input {:type :text
- :style {:width "90%" :margin :auto}
- :placeholder "Suche"
- :hx-get "/components/search"
- :name "query"
- :hx-swap "innerHTML"
- :hx-target "#search-results"}]
- [:div {:id "search-results"}]]))
+ (let [category (->> {:select [:*]
+ :from [:categories]
+ :where [:= :id (or (get-in req [:params "category"]) -1)]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first)]
+ [:div {:style {:text-align :center}}
+ [:h1 "chef"]
+ [:h2 "Finde das perfekte Gericht für dich!"]
+ [:b (:categories/question category)]
+ [:div
+ (for [child-category (->> {:select [:*]
+ :from [:categories]
+ :where [:= :parent (:categories/id category)]}
+ sql/format
+ (jdbc/execute! @cdb/db))]
+ [:div
+ [:button {:style {:margin-bottom "1em"}
+ :onclick (str "window.location = \"/?category=" (:categories/id child-category) "\"")}
+ (:categories/name child-category)]
+ [:br]])]
+ (when (pos? (:categories/id category))
+ [:h3 (cutils/category-path category)])
+ [:input {:type :text
+ :style {:width "90%" :margin :auto}
+ :placeholder "Suche"
+ :hx-get (str "/components/search?category=" (:categories/id category))
+ :name "query"
+ :hx-swap "innerHTML"
+ :hx-target "#search-results"}]
+ [:div {:id "search-results"}
+ (ccsearch/render "" (:categories/id category))]])))
(defn handler [req]
- (-> (render)
+ (-> req
+ render
html/html
str
ruresp/response))