blob: 9bc82fb4709a9d3500abb5da3b6cd026095e058c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
(ns chef.pages.home
(: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.components.search :as ccsearch]))
(defn- render [req]
(cutils/gen-page "chef"
(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]
(-> req
render
html/html
str
ruresp/response))
|