Syndicate to Day One from Admin pages

This commit is contained in:
2023-06-11 14:25:30 +10:00
parent 0776283aae
commit 15cdd40f75
9 changed files with 89 additions and 0 deletions

View File

@@ -17,5 +17,9 @@ module Adamantium
config.logger.level = :debug config.logger.level = :debug
config.logger.stream = "log/hanami.log" config.logger.stream = "log/hanami.log"
config.shared_app_component_keys += [
"syndication.dayone"
]
end end
end end

View File

@@ -84,6 +84,8 @@ module Adamantium
delete "/posts/:id", to: "posts.delete" delete "/posts/:id", to: "posts.delete"
post "/posts/:id/archive", to: "posts.archive" post "/posts/:id/archive", to: "posts.archive"
post "/posts/:id/publish", to: "posts.publish" post "/posts/:id/publish", to: "posts.publish"
get "/posts/:id", to: "posts.show"
post "/posts/:id/syndicate/:target", to: "posts.syndicate"
get "/media", to: "photos.index" get "/media", to: "photos.index"

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
module Admin
module Actions
module Posts
class Show < Admin::Action
include Deps["views.posts.show"]
def handle(req, res)
res.render show, id: req.params[:id]
end
end
end
end
end

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
module Admin
module Actions
module Posts
class Syndicate < Admin::Action
include Deps["commands.posts.syndicate"]
def handle(req, res)
syndicate.(post_id: req.params[:id], target: req.params[:target])
end
end
end
end
end

View File

@@ -0,0 +1,20 @@
require "readability"
require "down"
module Admin
module Commands
module Posts
class Syndicate
include Dry::Monads[:result]
include Deps["repos.post_repo", "syndication.dayone"]
def call(post_id:, target:)
post = post_repo.find(id: post_id)
dayone.(name: post[:name], content: post[:content]) if target.to_sym == :day_one
Success()
end
end
end
end
end

View File

@@ -41,6 +41,10 @@ module Admin
.to_a .to_a
end end
def find(id:)
posts.where(id: id).one!
end
def delete(id:) def delete(id:)
posts.where(id: id).delete posts.where(id: id).delete
end end

View File

@@ -20,6 +20,8 @@ div class="max-w-prose mx-auto" x-data="{ activeTab: 0 }"
small class="text-gray-400 dark:text-gray-600" = post.slug small class="text-gray-400 dark:text-gray-600" = post.slug
td td
= post.published_at&.strftime("%d %b %Y") = post.published_at&.strftime("%d %b %Y")
td
a href="/admin/posts/#{post.id}" edit
td td
button class="text-red-600" hx-delete="/admin/posts/#{post.id}" hx-target="#post-#{post.id}" delete button class="text-red-600" hx-delete="/admin/posts/#{post.id}" hx-target="#post-#{post.id}" delete
td td
@@ -34,6 +36,8 @@ div class="max-w-prose mx-auto" x-data="{ activeTab: 0 }"
small class="text-gray-400 dark:text-gray-600" = post.slug small class="text-gray-400 dark:text-gray-600" = post.slug
td td
= post.published_at&.strftime("%d %b %Y") = post.published_at&.strftime("%d %b %Y")
td
a href="/admin/posts/#{post.id}" edit
td td
button class="text-red-600" hx-delete="/admin/posts/#{post.id}" hx-target="#post-#{post.id}" delete button class="text-red-600" hx-delete="/admin/posts/#{post.id}" hx-target="#post-#{post.id}" delete
td td

View File

@@ -0,0 +1,12 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 bg-red-100"
h3 Syndicated to
ul
- post.syndication_sources.to_a.each do |name, url|
li
a href=url
= name
button hx-post="/admin/posts/#{post.id}/syndicate/day_one" Send to Day One
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
== post.content

View File

@@ -0,0 +1,13 @@
module Admin
module Views
module Posts
class Show < Admin::View
include Deps["repos.post_repo"]
expose :post do |id:|
post_repo.find(id: id)
end
end
end
end
end