diff --git a/slices/admin/actions/posts/add_syndication_source.rb b/slices/admin/actions/posts/add_syndication_source.rb new file mode 100644 index 0000000..381f192 --- /dev/null +++ b/slices/admin/actions/posts/add_syndication_source.rb @@ -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 diff --git a/slices/admin/commands/posts/add_syndication_source.rb b/slices/admin/commands/posts/add_syndication_source.rb new file mode 100644 index 0000000..985fc9b --- /dev/null +++ b/slices/admin/commands/posts/add_syndication_source.rb @@ -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 diff --git a/slices/admin/config/routes.rb b/slices/admin/config/routes.rb index daea836..a6f24ed 100644 --- a/slices/admin/config/routes.rb +++ b/slices/admin/config/routes.rb @@ -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") diff --git a/slices/admin/templates/posts/show.html.slim b/slices/admin/templates/posts/show.html.slim index e54b571..c1d481f 100644 --- a/slices/admin/templates/posts/show.html.slim +++ b/slices/admin/templates/posts/show.html.slim @@ -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