Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to see favorite gem files #19

Merged
merged 14 commits into from
Jan 20, 2024
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,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