Skip to content

Commit

Permalink
Create reviews UI
Browse files Browse the repository at this point in the history
  • Loading branch information
PaoloCappelli committed Nov 20, 2024
1 parent 925652e commit c3adc20
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/assets/stylesheets/_rating.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.rating-container {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
gap: 12px;
}

.rating-item {
display: flex;
align-items: center;
}

.interactive-star {
transition: transform 0.25s ease;

&:hover {
transform: scale(1.3);
}
}

.login-container {
display: flex;
gap: 4px;
align-items: center;
}
2 changes: 2 additions & 0 deletions app/controllers/subjects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def index
end

def show
@user_review = current_user.reviews.find_by(subject:) if current_user

respond_to do |format|
format.html { subject }
end
Expand Down
33 changes: 33 additions & 0 deletions app/views/subjects/_rating.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<label class="mdc-deprecated-list-item">
Puntuación:
<div class="rating-container">
<div class="rating-item">
<button class="material-icons mdc-icon-button">star</button>
<%= @subject.average_rating.present? ? @subject.average_rating : "Sin calificar" %>
</div>
<% if current_user %>
<div class="rating-item">
<% for value in 1..5 %>
<% filled = @user_review.present? && @user_review.rating >= value %>
<% selected = @user_review.present? && @user_review.rating == value %>
<% url = selected || @user_review.present? ? review_path(@user_review) : reviews_path %>
<% method = selected ? :delete : (@user_review.present? ? :put : :post) %>
<%= form_with(url:, method:, local: true) do |f| %>
<%= f.hidden_field :subject_id, value: @subject.id %>
<%= f.hidden_field :rating, value: %>
<%= f.button filled ? 'star' : 'star_outline', class: "material-icons mdc-icon-button interactive-star" %>
<% end %>
<% end %>
</div>
<% else %>
<%= link_to new_user_session_path do %>
<div class="login-container">
Inicia sesión para calificar
<span class="material-symbols-outlined">
login
</span>
</div>
<% end %>
<% end %>
</div>
</label>
2 changes: 2 additions & 0 deletions app/views/subjects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Grupo: Desconocido
<% end %>
</label>

<%= render 'rating' %>
</div>
<hr class="mdc-deprecated-list-divider">

Expand Down

0 comments on commit c3adc20

Please sign in to comment.