src/views/components/root.lisp

DOWNLOAD
(defpackage murja.views.components.root
  (:use :cl :murja.newui :binding-arrows)
  (:import-from :murja.posts.post-db :get-titles-by-year)
  (:import-from :murja.middleware.db :*settings*)
  (:export :root-component))

(in-package :murja.views.components.root)

(defun sidebar-tree ()
  (let* ((sidebar-titles (->>
			   (get-titles-by-year)
			   (lisp-fixup:group-by "Year"))))
    (component :ul (:id "grouper")
	       (loop for year being the hash-keys of sidebar-titles
		     collecting (c :li ()
				   (c :details ()
				      (c :summary () (format nil "~a (~d)" year (length (gethash year sidebar-titles))))
				      (component :ul ()
						 (let ((by-month (lisp-fixup:group-by "Month" (gethash year sidebar-titles))))
						   (loop for month being the hash-keys of by-month
							 collecting (c :li ()
								       (c :details ()
									  (c :summary () (format nil "~a (~d)" month (length (gethash month by-month))))
									  (component :ul ()
										     (map 'list
											  (lambda (title)
											    (cl-hash-util:with-keys ("Id" "Title") title
											      (c :li () (c :a (:href (format nil "/blog/post/~d" Id)) Title))))
											  (gethash month by-month))))))))))))))

(defun root-component (inner-component)
  "Returns the root html element of murja with `inner-component` embedded inside it"
  
  (c :html ()
     (c :head ()
	(c :link (:href "/resources/murja.css" :rel "stylesheet" :type "text/css"))
	(c :script (:src "https://unpkg.com/ace-custom-element@latest/dist/index.min.js" :type "module"))
	(c :script (:src "/resources/newui.js"))
	(c :meta (:charset "UTF-8")))
     (c :body ()
	(c :header ()
	   (c :a (:href "/") (gethash "blog-title" *settings* )))

	(c :div (:class "sidebar-flex")
	   inner-component

	   (c :div (:id "sidebar")
	      (c :form () ;; todo lol
		 (c :label () "Username " (c :input (:id "username" :name "username" :data-testid "username-input-field")))
		 (c :label () "Password " (c :input (:id "password" :name "password" :type "password" :data-testid "password-input-field"))))

	      (sidebar-tree))))))