(ns lezer.view.main (:require phel.router :as r) (:require phel.html :refer [html doctype raw-string]) (:require phel.string :as str)) (def- head [:head [:meta {:charset "utf-8"}] [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}] [:link {:rel "stylesheet" :href "./css/style.css"}] [:link {:rel "icon" :type "image/png" :href "./images/favicon-32.png"}] [:title "Lezer"]]) (defn- authors-list [authors router] (raw-string (html [:span (let [a (first authors)] (if a [:a {:href (r/generate router :author {:id (:id (first authors))})} (:name (first authors))])) (for [a :in (rest authors)] [:span ", " [:a {:href (r/generate router :author {:id (:id a)})} (:name a)]])]))) (defn index-html [books router] (html (doctype :html5) [:html head [:body [:header [:h1 "Lezer"]] [:main [:ul (for [b :in books] [:li (:title (:book b)) " by " (authors-list (:authors b) router) " " [:form {:action (str "/book/" (:id (:book b)) "/session") :method "POST"} [:button "Start"]]])]] [:aside [:h2 "Add new book"] [:div {:class "flex-center position-ref full-height"} [:form {:action "/book" :method "POST"} [:label {:for "title"} "Title: "] [:input {:type "text" :name "title"}] [:br] [:label {:for "subtitle"} "Subtitle: "] [:input {:type "text" :name "subtitle"}] [:br] [:label {:for "author"} "Author: "] [:input {:type "text" :name "author"}] [:br] [:label {:for "pages"} "# of pages: "] [:input {:type "number" :name "pages"}] [:input {:type "submit"}]]]]]]))