Add the about page and the about content form to the admin panel.

This commit is contained in:
2024-04-18 22:09:28 +03:00
parent 38e89bc2db
commit 60f943d2ca
3 changed files with 74 additions and 2 deletions
+36 -1
View File
@@ -24,6 +24,25 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn about-page-handler-factory
[client]
(fn [req res]
(let [channel (chan)
session (.-user (.-session req))]
(go
(try
(let [about (<! (db/get-about client channel))
content (:content about)]
(res/status 200)
(.render res "about"
(-> {:content content
:authorized (some? session)
:url "/about"}
(clj->js))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn login-page-handler-factory
[]
(fn [req res]
@@ -95,10 +114,12 @@
(try
(let [articles (if (nil? search)
(<! (db/get-articles-briefly client channel))
(<! (db/search-articles-briefly client search channel)))]
(<! (db/search-articles-briefly client search channel)))
about-content (:content (<! (db/get-about client channel)))]
(res/status 200)
(.render res "admin_panel"
(-> {:articles articles
:about-content about-content
:authorized (some? session)
:url "/admin"}
(clj->js))))
@@ -237,6 +258,20 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-update-about-handler-factory
[client]
(fn [req res]
(let [channel (chan)
content (.-content (.-body req))]
(go
(try
(let [id (<! (db/update-about client content channel))]
(res/status 200)
(.send res ""))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-admin-search-articles-handler-factory
[client]
(fn [req res]
+10 -1
View File
@@ -75,6 +75,9 @@
(. app get "/"
(handlers/index-page-handler-factory client))
(. app get "/about"
(handlers/about-page-handler-factory client))
(. app get "/login"
(handlers/login-page-handler-factory))
@@ -84,7 +87,6 @@
(. app get "/logout"
(handlers/logout-page-handler-factory))
(. app get "/admin"
handlers/is-user-authorized
(handlers/admin-panel-handler-factory client))
@@ -92,6 +94,13 @@
(. app use "/admin"
(handlers/user-not-authorized-factory))
(. app patch "/htmx/about/"
handlers/is-user-authorized
(handlers/htmx-update-about-handler-factory client))
(. app use "/htmx/about/"
(handlers/user-not-authorized-factory))
(. app post "/htmx/search/articles/"
(handlers/htmx-search-articles-handler-factory client))