Allow editing of posts
This commit is contained in:
14
slices/admin/actions/posts/update.rb
Normal file
14
slices/admin/actions/posts/update.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
module Admin
|
||||
module Actions
|
||||
module Posts
|
||||
class Update < Action
|
||||
include Deps["commands.posts.update"]
|
||||
|
||||
def handle(req, res)
|
||||
update.(params: req.params)
|
||||
res.redirect "/admin/posts/#{req.params[:id]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
slices/admin/commands/posts/update.rb
Normal file
19
slices/admin/commands/posts/update.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Admin
|
||||
module Commands
|
||||
module Posts
|
||||
class Update
|
||||
include Deps[
|
||||
"repos.post_repo",
|
||||
"renderers.markdown"
|
||||
]
|
||||
|
||||
def call(params:)
|
||||
attrs_to_replace = {}
|
||||
attrs_to_replace[:content] = markdown.call(content: params[:body]) if params[:body]
|
||||
|
||||
post_repo.update(params[:id], attrs_to_replace)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -36,6 +36,7 @@ module Admin
|
||||
post "/posts/:id/publish", to: Auth.call(action: "posts.publish")
|
||||
get "/posts/:id", to: Auth.call(action: "posts.show")
|
||||
post "/posts/:id/syndicate/:target", to: Auth.call(action: "posts.syndicate")
|
||||
post "/post/:id/update", to: Auth.call(action: "posts.update")
|
||||
|
||||
get "/media", to: Auth.call(action: "photos.index")
|
||||
delete "/media/public/media/:year/:path", to: Auth.call(action: "photos.delete")
|
||||
|
@@ -3,6 +3,8 @@ require "time_math"
|
||||
module Admin
|
||||
module Repos
|
||||
class PostRepo < Adamantium::Repo[:posts]
|
||||
commands update: :by_pk
|
||||
|
||||
def tag_post(post_id:, tag_id:)
|
||||
return if posts
|
||||
.post_tags
|
||||
|
@@ -8,8 +8,12 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
|
||||
= name
|
||||
button hx-post="/admin/posts/#{post.id}/syndicate/day_one" Send to Day One
|
||||
|
||||
// TODO: Add preview, save post, fix sending to DayOne
|
||||
// TODO: Add preview, fix sending to DayOne
|
||||
article class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline prose-img:rounded"
|
||||
h1= post.name
|
||||
textarea class="text-gray-800 w-full border-blue-200 border-2 rounded p-2" x-data="{ resize: () => { $el.style.height = '5px'; $el.style.height = $el.scrollHeight + 'px' } }" x-init="resize()" @input="resize()"
|
||||
== markdown_body
|
||||
a href="/post/#{post.slug}"
|
||||
h1= post.name
|
||||
form action="/admin/post/#{post.id}/update" method="POST"
|
||||
textarea name="body" class="text-gray-800 w-full border-blue-200 border-2 rounded p-2" x-data="{ resize: () => { $el.style.height = '5px'; $el.style.height = $el.scrollHeight + 'px' } }" x-init="resize()" @input="resize()"
|
||||
== markdown_body
|
||||
button class="rounded bg-blue-100 hover:bg-blue-200 text-blue-600 px-2 hover:cursor-pointer" type="submit"
|
||||
= "Update"
|
||||
|
Reference in New Issue
Block a user