Allow adding of syndication sources after a post is created
This commit is contained in:
21
slices/admin/actions/posts/add_syndication_source.rb
Normal file
21
slices/admin/actions/posts/add_syndication_source.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Actions
|
||||
module Posts
|
||||
class AddSyndicationSource < Admin::Action
|
||||
include Deps["commands.posts.add_syndication_source"]
|
||||
|
||||
def handle(req, res)
|
||||
add_syndication_source.call(post_id: req.params[:id],
|
||||
source_name: req.params[:syndication_source_name],
|
||||
source_url: req.params[:syndication_source_url]
|
||||
)
|
||||
|
||||
res.status = 201
|
||||
res.headers["HX-Refresh"] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
22
slices/admin/commands/posts/add_syndication_source.rb
Normal file
22
slices/admin/commands/posts/add_syndication_source.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require "readability"
|
||||
require "down"
|
||||
|
||||
module Admin
|
||||
module Commands
|
||||
module Posts
|
||||
class AddSyndicationSource
|
||||
include Dry::Monads[:result]
|
||||
include Deps["repos.post_repo"]
|
||||
|
||||
def call(post_id:, source_name:, source_url:)
|
||||
post = post_repo.find(id: post_id)
|
||||
syndication_sources = post[:syndication_sources]
|
||||
updated_syndication_sources = syndication_sources.merge(source_name => source_url)
|
||||
|
||||
post_repo.update(post_id, syndication_sources: updated_syndication_sources)
|
||||
Success()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -35,6 +35,7 @@ module Admin
|
||||
post "/posts/:id/archive", to: Auth.call(action: "posts.archive")
|
||||
post "/posts/:id/publish", to: Auth.call(action: "posts.publish")
|
||||
get "/posts/:id", to: Auth.call(action: "posts.show")
|
||||
post "/posts/:id/syndicate/add_source", to: Auth.call(action: "posts.add_syndication_source")
|
||||
post "/posts/:id/syndicate/:target", to: Auth.call(action: "posts.syndicate")
|
||||
post "/post/:id/update", to: Auth.call(action: "posts.update")
|
||||
|
||||
|
@@ -1,11 +1,23 @@
|
||||
|
||||
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 bg-red-100"
|
||||
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200 bg-pink-100 p-4 rounded"
|
||||
h3 Syndicated to
|
||||
ul
|
||||
- post.syndication_sources.to_a.each do |name, url|
|
||||
li
|
||||
a href=url
|
||||
= name
|
||||
form hx-post="/admin/posts/#{post.id}/syndicate/add_source"
|
||||
span class="mr-2"
|
||||
label for="syndication_source_name"
|
||||
' Name:
|
||||
select id="syndication_source_name" name="syndication_source_name"
|
||||
option value="" (none)
|
||||
option value="mastodon" Mastodon
|
||||
span class="mr-2"
|
||||
label for="syndication_source_url"
|
||||
' URL:
|
||||
input type="text" id="syndication_source_url" name="syndication_source_url"
|
||||
button type="submit" Add source
|
||||
button hx-post="/admin/posts/#{post.id}/syndicate/day_one" Send to Day One
|
||||
|
||||
// TODO: Add preview, fix sending to DayOne
|
||||
|
Reference in New Issue
Block a user