Skip to content

Commit

Permalink
Add historical match filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxagon committed Jun 4, 2024
1 parent 1cb7c68 commit 904e728
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
!/app/assets/builds/.keep

.irb_history

.DS_Store
10 changes: 10 additions & 0 deletions app/controllers/recent_matches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def index
@recent_matches = CollectsRecentMatchesForUser.new.call(user: @current_user)
end

def filter
load_current_user_profile

@historical_matches = HistoricalMatch.where(filter_params).order(matched_on: :desc)
end

private

def load_current_user_profile
Expand All @@ -15,4 +21,8 @@ def load_current_user_profile

@user_profile = SlackUserProfile.find_by(slack_user_id: @current_user.slack_user_id)
end

def filter_params
params.permit(:grouping)
end
end
24 changes: 24 additions & 0 deletions app/views/recent_matches/_historical_match.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div id="historical_match_<%= historical_match.id %>" class="my-4 px-4">
<div class="flex flex-col space-y-4 border border-black">
<div class="flex flex-wrap">
<% historical_match.profiled_members.each do |member| %>
<%= link_to profile_path(member.slack_user_id) do %>
<div class="flex flex-row p-2">
<img class="w-8 h-8" src="<%= member.avatar_url %>" />
<span class="leading-8 px-2"><%= member.name %></span>
</div>
<% end %>
<% end %>
</div>
<div class="flex flex-row justify-between">
<div class="text-sm text-slate-500 m-1">
<%= historical_match.grouping.titleize %>
</div>
<div class="text-sm text-slate-500 m-1">
<div>
<span><%= historical_match.matched_on.strftime("%b %d, %Y") %></span>
</div>
</div>
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions app/views/recent_matches/filter.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="w-full">
<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">Historical matches</h1>
</div>

<div id="historical_matches" class="min-w-full">
<% if @historical_matches.empty? %>
<p class="px-4">No matches made yet</p>
<% else %>
<%= render partial: "historical_match", collection: @historical_matches %>
<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
root to: "root#index"

get "/matches", to: "recent_matches#index", as: "recent_matches"
get "/matches/filter", to: "recent_matches#filter", as: "filter_recent_matches"
get "/profile/:slack_user_id", to: "profile#show", as: "profile"
resources :calendar_links, except: [:show]

Expand Down

0 comments on commit 904e728

Please sign in to comment.