summaryrefslogtreecommitdiff
path: root/src/chef/frontend/visitor/home.clj
blob: 650398322383e7850c1c2bad361dfbb46228ac50 (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
(ns chef.frontend.visitor.home
  (:require [hiccup2.core :as html]
            [ring.util.response :as ruresp]
            [chef.utils :as cutils]

            [chef.frontend.visitor.search :as cfvsearch]

            [chef.logic.categories :as clcategories]))

(defn- render [req]
  (cutils/gen-page "chef"
                   (let [category (clcategories/get-category (or (get-in req [:params "category"]) -1))]
                     [:div {:style {:text-align :center}}
                      [:h1 "chef"]
                      [:h2 "Finde das perfekte Gericht für dich!"]
                      [:b (:categories/question category)]
                      [:div
                       (for [child-category (clcategories/find-categories-with-parent (:categories/id category))]
                         [: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 (clcategories/generate-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"}
                       (cfvsearch/render "" (:categories/id category))]])))

(defn handler [req]
  (-> req
      render
      html/html
      str
      ruresp/response))