Created
February 26, 2021 05:06
-
-
Save catmando/47150490125ccdfed5b4c2d9117d2a2e to your computer and use it in GitHub Desktop.
hyperstack vs hotwire - show_tweet.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShowTweet < HyperComponent | |
param :tweet | |
render(DIV, class: "card card-body") do | |
DIV { tweet.body } unless @editing | |
DIV(class: "mt-2") do | |
BUTTON { "Likes (#{tweet.likes_count})" }.on(:click) { tweet.increment!(:likes_count) } | |
BUTTON { "Retweets (#{tweet.retweets_count})" }.on(:click) { tweet.increment!(:retweets_count) } | |
if @editing | |
EditTweet(tweet: tweet, cancel_button: true) | |
.on(:saved, :canceled) { mutate @editing = false } | |
else | |
BUTTON { 'Edit Tweet' }.on(:click) { mutate @editing = true } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment