Ability to remove posts from trips
This commit is contained in:
@@ -93,6 +93,7 @@ module Adamantium
|
||||
get "/trips/:id", to: "trips.show"
|
||||
post "/trips", to: "trips.create"
|
||||
post "/trips/add_post", to: "trips.add_post"
|
||||
post "/trips/remove_post", to: "trips.remove_post"
|
||||
get "/trips/new", to: "trips.new"
|
||||
post "/trips/:id", to: "trips.update"
|
||||
end
|
||||
|
File diff suppressed because one or more lines are too long
15
slices/admin/actions/trips/remove_post.rb
Normal file
15
slices/admin/actions/trips/remove_post.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Actions
|
||||
module Trips
|
||||
class RemovePost < Admin::Action
|
||||
include Deps["commands.trips.remove_post"]
|
||||
|
||||
def handle(req, res)
|
||||
remove_post.call(post_id: req.params[:post_id], trip_id: req.params[:trip_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
slices/admin/commands/trips/remove_post.rb
Normal file
16
slices/admin/commands/trips/remove_post.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Admin
|
||||
module Commands
|
||||
module Trips
|
||||
class RemovePost
|
||||
include Dry::Monads[:result]
|
||||
include Deps["repos.post_trip_repo"]
|
||||
|
||||
def call(trip_id:, post_id:)
|
||||
post_trip_repo.remove(trip_id: trip_id, post_id: post_id)
|
||||
|
||||
Success()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -2,6 +2,10 @@ module Admin
|
||||
module Repos
|
||||
class PostTripRepo < Adamantium::Repo[:post_trips]
|
||||
commands :create
|
||||
|
||||
def remove(trip_id:, post_id:)
|
||||
post_trips.where(trip_id: trip_id, post_id: post_id).delete
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,15 +1,20 @@
|
||||
div class="mb-8 h-entry"
|
||||
- if !added
|
||||
button class="text-blue-600" hx-post="/admin/trips/add_post" hx-vals='{"trip_id": "#{trip_id}", "post_id": "#{post.id}"}'
|
||||
= "Add to trip"
|
||||
h3 class="text-xl font-semibold text-blue-600 mb-2"
|
||||
a class="border-b-2 border-transparent hover:border-blue-600 hover:border-b-2" href="/post/#{post.slug}"
|
||||
== post.content
|
||||
div class="e-content prose-p:mb-0 prose-img:my-2 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline p-name text-base prose prose-ul:list-none prose-ul:pl-0 prose-li:pl-0 text-gray-800 dark:text-gray-200 prose-a:dark:text-gray-100"
|
||||
div class="grid gap-4 grid-flow-row grid-cols-4 grid-rows-1"
|
||||
-post.photos.each do |photo|
|
||||
img class="w-44 h-44 object-cover rounded" src=photo["value"]
|
||||
td
|
||||
- if added
|
||||
button class="text-red-200 bg-red-400 hover:bg-red-100 rounded p-2 dark:text-red-900" hx-post="/admin/trips/remove_post" hx-vals='{"trip_id": "#{trip_id}", "post_id": "#{post.id}"}'
|
||||
= "Remove"
|
||||
- else
|
||||
button class="text-blue-200 bg-blue-400 hover:bg-blue-100 rounded p-2 dark:text-blue-900" hx-post="/admin/trips/add_post" hx-vals='{"trip_id": "#{trip_id}", "post_id": "#{post.id}"}'
|
||||
= "Add"
|
||||
td
|
||||
h3 class="text-xl font-semibold text-blue-600 mb-2"
|
||||
a class="border-b-2 border-transparent hover:border-blue-600 hover:border-b-2" href="/post/#{post.slug}"
|
||||
== post.content
|
||||
div class="e-content prose-p:mb-0 prose-img:my-2 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline p-name text-base prose prose-ul:list-none prose-ul:pl-0 prose-li:pl-0 text-gray-800 dark:text-gray-200 prose-a:dark:text-gray-100"
|
||||
div class="grid gap-4 grid-flow-row grid-cols-4 grid-rows-1"
|
||||
-post.photos.each do |photo|
|
||||
img class="w-44 h-44 object-cover rounded" src=photo["value"]
|
||||
|
||||
p class="text-sm text-blue-400"
|
||||
a href="/post/#{post.slug}"
|
||||
= post.published_at
|
||||
p class="text-sm text-blue-400"
|
||||
a href="/post/#{post.slug}"
|
||||
= post.published_at
|
||||
|
@@ -18,7 +18,9 @@ div class="max-w-prose mx-auto mb-8 border-gray-400 border-b-4"
|
||||
= "Update"
|
||||
|
||||
div class="max-w-prose mx-auto"
|
||||
- posts.each do |post|
|
||||
== render "shared/post", post: post, trip_id: trip.id, added: post.trips.map(&:id).include?(trip.id)
|
||||
table
|
||||
- posts.each do |post|
|
||||
tr
|
||||
== render "shared/post", post: post, trip_id: trip.id, added: post.trips.map(&:id).include?(trip.id)
|
||||
|
||||
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"
|
||||
|
Reference in New Issue
Block a user