diff --git a/app/assets/stylesheets/splats.css b/app/assets/stylesheets/splats.css index 805acf8cc..45d851487 100644 --- a/app/assets/stylesheets/splats.css +++ b/app/assets/stylesheets/splats.css @@ -52,6 +52,7 @@ @media (hover: hover) { .windshield &:hover { scale: 1.1; + z-index: 999; .splat__svg { transform: rotate(calc(var(--splat-rotate) + 10deg)); @@ -83,6 +84,10 @@ aspect-ratio: 1; inset: 50cqi -1cqi auto auto; + a { + text-decoration: none; + } + .windshield .splat:hover & { transform: translate(0, 1rem) !important; } diff --git a/app/controllers/boosts_controller.rb b/app/controllers/boosts_controller.rb new file mode 100644 index 000000000..398874e7c --- /dev/null +++ b/app/controllers/boosts_controller.rb @@ -0,0 +1,26 @@ +class BoostsController < ApplicationController + before_action :set_splat + + def new + @boost = @splat.boosts.build + end + + def create + @boost = @splat.boosts.new + @boost.save + + respond_to do |format| + format.turbo_stream { render } + format.html { head :no_content } + end + end + + def index + @boosts = @splat.boosts + end + + private + def set_splat + @splat = Splat.find(params[:splat_id]) + end +end diff --git a/app/helpers/boosts_helper.rb b/app/helpers/boosts_helper.rb new file mode 100644 index 000000000..72ee165ae --- /dev/null +++ b/app/helpers/boosts_helper.rb @@ -0,0 +1,2 @@ +module BoostsHelper +end diff --git a/app/javascript/controllers/auto_submit_controller.js b/app/javascript/controllers/auto_submit_controller.js new file mode 100644 index 000000000..2fa3a4ae4 --- /dev/null +++ b/app/javascript/controllers/auto_submit_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.requestSubmit() + } +} diff --git a/app/views/boosts/_boost.html.erb b/app/views/boosts/_boost.html.erb new file mode 100644 index 000000000..aef492e56 --- /dev/null +++ b/app/views/boosts/_boost.html.erb @@ -0,0 +1 @@ +<%= link_to splat.boosts.any? ? "+ #{splat.boosts.size}" : "+", new_splat_boost_path(splat) %> diff --git a/app/views/boosts/create.turbo_stream.erb b/app/views/boosts/create.turbo_stream.erb new file mode 100644 index 000000000..1a7fb26fd --- /dev/null +++ b/app/views/boosts/create.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update dom_id(@splat, "boosts") do %> + <%= render "/boosts/boost", splat: @splat %> +<% end %> diff --git a/app/views/boosts/index.html.erb b/app/views/boosts/index.html.erb new file mode 100644 index 000000000..c3eebad03 --- /dev/null +++ b/app/views/boosts/index.html.erb @@ -0,0 +1,3 @@ +"> + <%= render "/boosts/boost", splat: @splat %> + diff --git a/app/views/boosts/new.html.erb b/app/views/boosts/new.html.erb new file mode 100644 index 000000000..180f27376 --- /dev/null +++ b/app/views/boosts/new.html.erb @@ -0,0 +1,5 @@ +"> + <%= form_with model: [@splat, @boost], data: { controller: "auto-submit" } do |form| %> + <%= form.submit "Boost this", hidden: true %> + <% end %> + diff --git a/app/views/splats/_splat.html.erb b/app/views/splats/_splat.html.erb index 8e33b4033..b2dc16fc2 100644 --- a/app/views/splats/_splat.html.erb +++ b/app/views/splats/_splat.html.erb @@ -21,7 +21,8 @@ <% end %> - <% if splat.boosts.any? %> -
<%= splat.boosts.size %>
- <% end %> + +
+ " src="<%= splat_boosts_path(splat) %>" /> +
diff --git a/config/routes.rb b/config/routes.rb index 12b7555b3..d35b56025 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ Rails.application.routes.draw do resource :session resources :splats do + resources :boosts resources :categories, shallow: true resources :comments end diff --git a/test/controllers/boosts_controller_test.rb b/test/controllers/boosts_controller_test.rb new file mode 100644 index 000000000..051cf6298 --- /dev/null +++ b/test/controllers/boosts_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class BoostsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end