Skip to content

Commit

Permalink
Merge pull request #19 from varkum/vk/see-starred-gems
Browse files Browse the repository at this point in the history
Add functionality to see favorite gem files
  • Loading branch information
Shpigford authored Jan 20, 2024
2 parents ecd7c7a + a3ea6fa commit f76e031
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ GEM
PLATFORMS
aarch64-linux
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/my/favorites_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class My::FavoritesController < ApplicationController
def index
@favorite_gemfiles = current_user.favorite_gemfiles
end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def self.from_omniauth(omniauth_params)
user.save
user
end

def favorite_gemfiles
Gemfile.where(id: favorites.where(favoritable_type: "Gemfile").pluck(:favoritable_id)).with_favorites
end
end
4 changes: 1 addition & 3 deletions app/views/gemfiles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@
<% end %>

<ul role="list" class="divide-y divide-gray-100">
<% @gemfiles.each do |gemfile| %>
<%= render "gemfile_list_item", gemfile: gemfile %>
<% end %>
<%= render partial: "gemfile_list_item", collection: @gemfiles, as: :gemfile %>
</ul>
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@
</button>
</div>

<div class="absolute right-0 z-10 w-48 py-1 mt-2 origin-top-right bg-white rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1" data-dropdown-target="menu">
<div class="absolute right-0 z-10 w-48 py-1 mt-2 origin-top-right bg-white rounded-md divide-y shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1" data-dropdown-target="menu">
<!-- Active: "bg-gray-100", Not Active: "" -->
<%= button_to 'Sign out', sign_out_path, method: :delete, class: "block px-4 py-2 text-sm text-gray-700", data: { turbo: false } %>
<%= link_to "Favorite Gemfiles", my_favorites_path, class: "block px-4 py-2 text-sm text-gray-700" %>
<%= button_to 'Sign out', sign_out_path, method: :delete, class: "block bg-red-500 text-white mx-auto rounded mt-2 px-4 py-2 text-sm text-gray-700", data: { turbo: false } %>
</div>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions app/views/my/favorites/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%
title "My Favorite Gemfiles"
header_title "My Favorite Gemfiles"
%>

<ul role="list" class="divide-y divide-gray-100">
<%= render partial: "gemfiles/gemfile_list_item", collection: @favorite_gemfiles, as: :gemfile %>
<span class="italic text-sm text-gray-500 hidden only:inline-block">You don't have any favorite gemfiles yet.</span>
</ul>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

get "search", to: "search#index"

namespace :my do
resources :favorites, only: [ :index ]
end

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
Expand Down

0 comments on commit f76e031

Please # to comment.