From 5ebef72d3832274b91957f495e2c50033b4f3da6 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Tue, 12 Dec 2023 12:42:45 -0600 Subject: [PATCH] Add bounty filters --- app/controllers/bounties_controller.rb | 4 +++- app/models/bounty.rb | 1 + app/views/bounties/_bounty.html.erb | 17 +++++++---------- app/views/bounties/_hero.html.erb | 8 ++++---- app/views/bounties/index.html.erb | 12 ++++++++++-- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/controllers/bounties_controller.rb b/app/controllers/bounties_controller.rb index a0b459c..13abfef 100644 --- a/app/controllers/bounties_controller.rb +++ b/app/controllers/bounties_controller.rb @@ -5,7 +5,9 @@ class BountiesController < ApplicationController # GET /bounties or /bounties.json def index - @pagy, @bounties = pagy(Bounty.sorted) + @bounties = Bounty.sorted + @filter, @bounties = params[:filter], @bounties.filtered(params[:filter]) if Bounty::STATUSES.include?(params[:filter]) + @pagy, @bounties = pagy(@bounties) end # GET /bounties/1 or /bounties/1.json diff --git a/app/models/bounty.rb b/app/models/bounty.rb index 02203e0..4e0af52 100644 --- a/app/models/bounty.rb +++ b/app/models/bounty.rb @@ -5,6 +5,7 @@ class Bounty < ApplicationRecord has_rich_text :description scope :sorted, -> { in_order_of(:status, STATUSES).order(created_at: :desc) } + scope :filtered, ->(status) { where(status: status) } validates :amount, presence: true, numericality: {greater_than: 0, only_integer: true} validates :description, presence: true diff --git a/app/views/bounties/_bounty.html.erb b/app/views/bounties/_bounty.html.erb index c47fdfd..cd0941c 100644 --- a/app/views/bounties/_bounty.html.erb +++ b/app/views/bounties/_bounty.html.erb @@ -1,13 +1,9 @@
-
-
- <%= number_to_currency bounty.amount, precision: 0 %> -
+

<%= link_to bounty.title, bounty_path(bounty), class: "no-underline font-bold tracking-tight" %>

-

<%= link_to bounty.title, bounty_path(bounty) %>

-
Created by <%= bounty.user.name %>
- <%= simple_format truncate(bounty.description.to_plain_text, length: 1000) %> +
+ <%= number_to_currency bounty.amount, precision: 0 %>
@@ -15,10 +11,11 @@
<%= status_badge bounty.status %> - <%= link_to bounty.url, class: "no-underline flex items-center gap-1", target: :_blank do %> + <%= link_to bounty.url, class: "no-underline inline-flex gap-2 items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500", target: :_blank do %> View Project - - + + + <% end %>
diff --git a/app/views/bounties/_hero.html.erb b/app/views/bounties/_hero.html.erb index e724fe2..6496937 100644 --- a/app/views/bounties/_hero.html.erb +++ b/app/views/bounties/_hero.html.erb @@ -1,8 +1,8 @@ -
+
-

Small projects for Junior Developers

-

Help Junior developers get hired by sharing small projects they can work on to build their resume with paid work.

-
+

Small projects for Junior Developers

+

Help Junior developers get hired by sharing small projects they can work on to build their resume with paid work.

+
<%= link_to "Post a bounty", new_user_registration_path, class: "no-underline rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white" %> How it works
diff --git a/app/views/bounties/index.html.erb b/app/views/bounties/index.html.erb index 773ca62..0f90da4 100644 --- a/app/views/bounties/index.html.erb +++ b/app/views/bounties/index.html.erb @@ -2,10 +2,18 @@ <%= render 'hero' %> <% end %> -

All Bounties

+
+

<%= (@filter || "All").titleize %> Bounties

+ +
<%= render @bounties %>
-<%== pagy_nav(@pagy).html_safe %> \ No newline at end of file +<%== pagy_nav(@pagy).html_safe %>