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

feat(snippets): reactions #377

Merged
merged 15 commits into from
Dec 1, 2023
Merged

feat(snippets): reactions #377

merged 15 commits into from
Dec 1, 2023

Conversation

wJoenn
Copy link
Collaborator

@wJoenn wJoenn commented Nov 30, 2023

Summary of changes and context

closes #269

This is a MVP for the snipppets' reaction system.
Eventually I'd like to add a transition to the tooltip so that it fades in from the bottom but it's gonna need JavaScript.
I also want to be able to update reactions without reloading the page, or at least without scrolling back at the top.
It was might doable with Turbo ? I haven't really used it yet, otherwise it should easily be doable with JavaScript too.

Le.Wagon.x.Advent.of.Code.-.Brave.2023-11-30.20-04-11.mp4

I don't like the fact that one of the Snippets::ReactionComponent::initialize attributes is called emote instead of content but apparently the latter is a reserved keyword so I had to change it.
The reason I went with content is because that's what Github does with their API.

image

Sanity checks

  • Linters pass
  • Tests pass
  • Related GitHub issues are linked in the description

@wJoenn
Copy link
Collaborator Author

wJoenn commented Nov 30, 2023

AH
J'ai oublié de remettre les guards sur les routes après mes tests en local 😅

Copy link
Owner

@pil0u pil0u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Partie 1/2)

Ça fait plaisir de voir un bon vieux CRUD. Mes commentaires c'est que du nommage à ce stade.

J'ai pas encore review le front, je fais ça tout de suite

db/migrate/20231130162723_create_reactions.rb Show resolved Hide resolved
db/migrate/20231130162723_create_reactions.rb Outdated Show resolved Hide resolved
config/routes.rb Outdated Show resolved Hide resolved
config/routes.rb Show resolved Hide resolved
app/controllers/reactions_controller.rb Show resolved Hide resolved
app/models/reaction.rb Outdated Show resolved Hide resolved
app/models/reaction.rb Outdated Show resolved Hide resolved
app/models/reaction.rb Outdated Show resolved Hide resolved
}.freeze

def initialize(snippet:, reaction_type:, user:)
@user = user
Copy link
Collaborator

@Aquaj Aquaj Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça serait un bon cas d'utilisation pour Current.user afin de skipper le passage de @user à travers plusieurs couches nestées (View -> Component -> View -> ici) juste pour arriver ici.

(Pas bloquant, je dis juste pour garder en tête des refactos possibles)

app/controllers/reactions_controller.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

app/models/reaction.rb Outdated Show resolved Hide resolved
@Aquaj
Copy link
Collaborator

Aquaj commented Dec 1, 2023

Ready to merge quand tu te le sens, @pil0u.

Comment on lines +6 to +22
<% if @reactions.pluck(:user_id).include?(@user.id) %>
<%= button_to "#{EMOTES[@reaction_type][:emote]} #{@reactions.count}",
delete_reaction_path(id: @reactions.find_by(user: @user).id),
method: :delete,
class: "border border-aoc-green cursor-pointer duration-300 px-1.5 rounded-full transition-colors hover:bg-aoc-gray-darker" %>
<% elsif @snippet.reactions.pluck(:user_id).include?(@user.id) %>
<%= button_to "#{EMOTES[@reaction_type][:emote]} #{@reactions.count}",
update_reaction_path(id: @snippet.reactions.find_by(user: @user).id),
params: { reaction: { reaction_type: @reaction_type } },
method: :patch,
class: "border border-aoc-gray-dark cursor-pointer duration-300 px-1.5 rounded-full transition-colors hover:bg-aoc-gray-darker" %>
<% else %>
<%= button_to "#{EMOTES[@reaction_type][:emote]} #{@reactions.count}",
reactions_path(@snippet.id),
params: { reaction: { reaction_type: @reaction_type } },
class: "border border-aoc-gray-dark px-1.5 duration-300 rounded-full transition-colors #{'cursor-pointer hover:bg-aoc-gray-darker' unless @snippet.reactions.pluck(:user_id).include?(@user.id)}" %>
<% end %>
Copy link
Collaborator

@Aquaj Aquaj Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplifiable avec un chouïa de dynamisme et en passant par 1 seule action de controller au lieu de trois (que ça soit le back qui gère cette logique).
Mais pas bloquant, on pourra refaire plus tard.

@pil0u pil0u merged commit a762e4b into main Dec 1, 2023
5 checks passed
@pil0u pil0u deleted the feat/snippets/reactions branch December 1, 2023 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permettre aux utilisateurs de voter sur les snippets en émojis
3 participants