From 9177e42fb08ae7b5078ee2fdf0f84afd3527c71a Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 10 Apr 2024 12:46:09 +0300 Subject: [PATCH] Add the create modal, a route, a handler to create a article. --- src/main/blog/handlers.cljs | 20 ++++++++++++++++ src/main/blog/server.cljs | 10 ++++++++ views/admin_panel.hbs | 46 ++++++++++++++++++++++++++++++++++--- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/main/blog/handlers.cljs b/src/main/blog/handlers.cljs index 56080ab..d601435 100644 --- a/src/main/blog/handlers.cljs +++ b/src/main/blog/handlers.cljs @@ -98,3 +98,23 @@ (res/status 500) (res/send (ex-message err)))))))) +(defn htmx-create-article-handler-factory + [client] + (fn [req res] + (let [channel (chan) + title (.-title (.-body req)) + content (.-content (.-body req))] + (go + (try + (let [id ( {:extended false} + (clj->js)))) + (. app get "/" (handlers/index-page-handler-factory client)) (fn [req res] @@ -35,6 +42,9 @@ (. app get "/admin" (handlers/admin-panel-handler-factory client)) + (. app post "/htmx/articles/" + (handlers/htmx-create-article-handler-factory client)) + (. app get "/htmx/articles/:id" (handlers/htmx-get-article-handler-factory client)) diff --git a/views/admin_panel.hbs b/views/admin_panel.hbs index f7d854d..ba6d494 100644 --- a/views/admin_panel.hbs +++ b/views/admin_panel.hbs @@ -34,9 +34,8 @@
+ + +