Ability to remove posts from trips
This commit is contained in:
@@ -93,6 +93,7 @@ module Adamantium
|
|||||||
get "/trips/:id", to: "trips.show"
|
get "/trips/:id", to: "trips.show"
|
||||||
post "/trips", to: "trips.create"
|
post "/trips", to: "trips.create"
|
||||||
post "/trips/add_post", to: "trips.add_post"
|
post "/trips/add_post", to: "trips.add_post"
|
||||||
|
post "/trips/remove_post", to: "trips.remove_post"
|
||||||
get "/trips/new", to: "trips.new"
|
get "/trips/new", to: "trips.new"
|
||||||
post "/trips/:id", to: "trips.update"
|
post "/trips/:id", to: "trips.update"
|
||||||
end
|
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
|
module Repos
|
||||||
class PostTripRepo < Adamantium::Repo[:post_trips]
|
class PostTripRepo < Adamantium::Repo[:post_trips]
|
||||||
commands :create
|
commands :create
|
||||||
|
|
||||||
|
def remove(trip_id:, post_id:)
|
||||||
|
post_trips.where(trip_id: trip_id, post_id: post_id).delete
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,15 +1,20 @@
|
|||||||
div class="mb-8 h-entry"
|
div class="mb-8 h-entry"
|
||||||
- if !added
|
td
|
||||||
button class="text-blue-600" hx-post="/admin/trips/add_post" hx-vals='{"trip_id": "#{trip_id}", "post_id": "#{post.id}"}'
|
- if added
|
||||||
= "Add to trip"
|
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}"}'
|
||||||
h3 class="text-xl font-semibold text-blue-600 mb-2"
|
= "Remove"
|
||||||
a class="border-b-2 border-transparent hover:border-blue-600 hover:border-b-2" href="/post/#{post.slug}"
|
- else
|
||||||
== post.content
|
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}"}'
|
||||||
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"
|
= "Add"
|
||||||
div class="grid gap-4 grid-flow-row grid-cols-4 grid-rows-1"
|
td
|
||||||
-post.photos.each do |photo|
|
h3 class="text-xl font-semibold text-blue-600 mb-2"
|
||||||
img class="w-44 h-44 object-cover rounded" src=photo["value"]
|
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"
|
p class="text-sm text-blue-400"
|
||||||
a href="/post/#{post.slug}"
|
a href="/post/#{post.slug}"
|
||||||
= post.published_at
|
= post.published_at
|
||||||
|
@@ -18,7 +18,9 @@ div class="max-w-prose mx-auto mb-8 border-gray-400 border-b-4"
|
|||||||
= "Update"
|
= "Update"
|
||||||
|
|
||||||
div class="max-w-prose mx-auto"
|
div class="max-w-prose mx-auto"
|
||||||
- posts.each do |post|
|
table
|
||||||
== render "shared/post", post: post, trip_id: trip.id, added: post.trips.map(&:id).include?(trip.id)
|
- 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"
|
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