Add the search for articles for the admin panel.

This commit is contained in:
2024-04-14 22:09:00 +03:00
parent dd72f8d489
commit 6d3eefcd35
4 changed files with 45 additions and 12 deletions
+21 -2
View File
@@ -26,10 +26,12 @@
[client]
(fn [req res]
(let [channel (chan)
id (.-id (.-params req))]
search (.-search (.-query req))]
(go
(try
(let [articles (<! (db/get-articles-briefly client channel))]
(let [articles (if (nil? search)
(<! (db/get-articles-briefly client channel))
(<! (db/search-articles-briefly client search channel)))]
(res/status 200)
(.render res "admin_panel"
(-> {:articles articles
@@ -133,6 +135,23 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-admin-search-articles-handler-factory
[client]
(fn [req res]
(let [channel (chan)
search (.-search (.-body req))]
(go
(try
(let [articles (<! (db/search-articles-briefly client search channel))]
(res/status 200)
(.render res "article_rows"
(-> {:articles articles
:layout false}
(cljs.core/clj->js))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-create-article-handler-factory
[client]
(fn [req res]
+3
View File
@@ -79,6 +79,9 @@
(. app get "/htmx/articles/:id"
(handlers/htmx-get-article-handler-factory client))
(. app post "/htmx/admin/search/articles/"
(handlers/htmx-admin-search-articles-handler-factory client))
(. app get "/htmx/admin/rows/article/:id/"
(handlers/htmx-get-article-row-handler-factory client))