From 250de0c4302c16407070d3d239edbcfe5675432f Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sat, 1 Jul 2023 12:20:03 +1000 Subject: [PATCH] Clean up trips UI --- app/decorators/posts/decorator.rb | 4 ++ slices/admin/repos/post_repo.rb | 2 +- slices/admin/templates/shared/_post.html.slim | 37 +++++++++---------- slices/admin/templates/trips/show.html.slim | 9 ++--- slices/admin/views/trips/show.rb | 4 +- tailwind.config.js | 2 +- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/app/decorators/posts/decorator.rb b/app/decorators/posts/decorator.rb index 33ebcd2..ef81d32 100644 --- a/app/decorators/posts/decorator.rb +++ b/app/decorators/posts/decorator.rb @@ -107,6 +107,10 @@ module Adamantium end end + def trips + __getobj__.trips + end + private # e.g. geo:-37.75188,144.90417;u=35 diff --git a/slices/admin/repos/post_repo.rb b/slices/admin/repos/post_repo.rb index ec64e8c..7de312b 100644 --- a/slices/admin/repos/post_repo.rb +++ b/slices/admin/repos/post_repo.rb @@ -62,8 +62,8 @@ module Admin posts .combine(:trips) - .where(post_type: %w[post check-in]) .published_between(start_date, end_date) + .to_a end end end diff --git a/slices/admin/templates/shared/_post.html.slim b/slices/admin/templates/shared/_post.html.slim index 3616ec0..37d73a5 100644 --- a/slices/admin/templates/shared/_post.html.slim +++ b/slices/admin/templates/shared/_post.html.slim @@ -1,20 +1,19 @@ -div class="mb-8 h-entry" - 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"] +div class="flex-initial w-36 px-8" + - if added + button class="w-full 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="w-full 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" +div class="flex-initial w-full" + 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.display_title + 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 diff --git a/slices/admin/templates/trips/show.html.slim b/slices/admin/templates/trips/show.html.slim index 63853f7..ad11dd9 100644 --- a/slices/admin/templates/trips/show.html.slim +++ b/slices/admin/templates/trips/show.html.slim @@ -17,10 +17,9 @@ div class="max-w-prose mx-auto mb-8 border-gray-400 border-b-4" button class="rounded bg-blue-100 hover:bg-blue-200 text-blue-600 px-2 hover:cursor-pointer" type="submit" = "Update" -div class="max-w-prose mx-auto" - 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="mb-12 max-w-prose mx-auto" + - posts.each do |post| + div class="flex flex-row" + == 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" diff --git a/slices/admin/views/trips/show.rb b/slices/admin/views/trips/show.rb index 6ab2453..97b6a4a 100644 --- a/slices/admin/views/trips/show.rb +++ b/slices/admin/views/trips/show.rb @@ -9,7 +9,9 @@ module Admin end expose :posts do |trip| - post_repo.created_between(trip.start_date, trip.end_date) + post_repo.created_between(trip.start_date, trip.end_date).map do |post| + Adamantium::Decorators::Posts::Decorator.new(post) + end end end end diff --git a/tailwind.config.js b/tailwind.config.js index cfbc831..b194f35 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -3,7 +3,7 @@ const colors = require("tailwindcss/colors"); module.exports = { - content: ["./app/templates/**/*.slim", "./public/assets/index.js", "app/decorators/*/decorator.rb"], + content: ["./app/templates/**/*.slim", "./slices/admin/templates/**/*.slim", "./public/assets/index.js", "app/decorators/*/decorator.rb"], theme: { fontSize: { xsm: '0.75rem',