Skip to content

Commit

Permalink
feat(snippets): filter by language (#402)
Browse files Browse the repository at this point in the history
* feat(snippets): add height-50 logos for every languages

* feat(snippets): add filter button to snippets

* fix(snippets): mobile query

* fix(snippets): moved h3 and add hover effect
  • Loading branch information
wJoenn authored Dec 4, 2023
1 parent a8e326c commit bd3e6f0
Show file tree
Hide file tree
Showing 25 changed files with 14 additions and 0 deletions.
Binary file added app/assets/images/languages/c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/cpp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/crystal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/csharp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/dart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/elixir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/go.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/haskell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/java.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/javascript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/kotlin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/markdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/matlab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/ocaml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/pascal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/php.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/r.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/ruby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/rust.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/sql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/swift.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/languages/typescript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/controllers/snippets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ class SnippetsController < ApplicationController
def show
@day = params[:day]
@challenge = params[:challenge]
@language = params[:language]

@snippet = Snippets::Builder.call(language: current_user.favourite_language)
@snippets = Snippet.includes(:user, :reactions).where(day: @day, challenge: @challenge).order(created_at: :desc)

@languages = @snippets.pluck(:language).uniq.sort
@snippets = @snippets.where(language: @language) if @language

@text_area_placeholder = <<~TEXT
This box is super smart.
Paste your code directly here, it will work.
Expand Down
10 changes: 10 additions & 0 deletions app/views/snippets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

<hr class="border-aoc-gray-darker">

<div class="mt-4 flex items-center gap-4 flex-wrap">
<h3>Filter by language</h3>

<% @languages.each do |language| %>
<%= link_to snippet_path(day: @day, challenge: @challenge, id: @snippet.id, language: @language == language ? nil : language), class: "h-4 lg:h-8" do %>
<%= image_tag "languages/#{language}.png", class: "h-full transition-all hover:opacity-100 #{'opacity-50' if @language.present? && @language != language}" %>
<% end %>
<% end %>
</div>

<div class="my-8 flex flex-col gap-y-4">
<%= render Snippets::BoxComponent.with_collection(@snippets, user: current_user) %>
</div>

0 comments on commit bd3e6f0

Please sign in to comment.