Skip to content

Commit

Permalink
Merge pull request #85 from ElsonOtake/turbo
Browse files Browse the repository at this point in the history
Turbo
  • Loading branch information
ElsonOtake authored Dec 19, 2023
2 parents 1b47ee4 + 4bfaabf commit d1fc391
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 45 deletions.
6 changes: 5 additions & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class CommentsController < ApplicationController
include TrackEvent
before_action :authenticate_member!
before_action :set_post, only: %i[new create]
before_action :set_post, only: %i[index new create]
before_action :set_comment, only: %i[edit update destroy]
before_action :set_event, only: %i[create update destroy]
after_action :track_event, only: %i[create update destroy]

def index
@comments = @post.comments.includes(:author)
end

def new
@comment = @post.comments.new
end
Expand Down
9 changes: 5 additions & 4 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class Member < ApplicationRecord
has_many :comments, foreign_key: 'author_id', dependent: :destroy
has_many :likes, foreign_key: 'author_id', dependent: :destroy
has_many :posts, foreign_key: 'author_id', dependent: :destroy
has_many :counter_analytics
has_many :browser_analytics
has_many :unique_analytics
has_many :length_analytics
has_many :counter_analytics, dependent: :destroy
has_many :browser_analytics, dependent: :destroy
has_many :unique_analytics, dependent: :destroy
has_many :length_analytics, dependent: :destroy
has_many :visitors, dependent: :destroy
has_one_attached :avatar do |attachable|
attachable.variant :thumb, resize_to_limit: [110, 110]
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/visitor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Visitor < ApplicationRecord
belongs_to :member, optional: true
has_many :counter_analytic
has_many :browser_analytics
has_many :unique_analytics
has_many :counter_analytic, dependent: :destroy
has_many :browser_analytics, dependent: :destroy
has_many :unique_analytics, dependent: :destroy
end
6 changes: 1 addition & 5 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<%= turbo_frame_tag comment do %>
<article class="media">
<figure class="media-left">
<p class="image is-48x48">
<%= render "members/thumb", member: comment.author %>
</p>
</figure>
<%= render "shared/thumbnail", member: comment.author %>
<div class="media-content">
<div class="content">
<p>
Expand Down
3 changes: 3 additions & 0 deletions app/views/comments/_comments.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% comments.each do |comment| %>
<%= render "comments/comment", comment: comment %>
<% end %>
6 changes: 1 addition & 5 deletions app/views/comments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<%= turbo_frame_tag @comment do %>
<article class="media pt-2" style="border-style:solid;border-color:#cdcdcd;border-width:0.1px 0px 0px;">
<figure class="media-left">
<p class="image is-48x48">
<%= render "members/thumb", member: current_member %>
</p>
</figure>
<%= render "shared/thumbnail", member: current_member %>
<div class="media-content">
<%= render "comments/form", url: member_post_comment_path(@comment.post.author, @comment.post, @comment), comment: @comment %>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/views/comments/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= turbo_frame_tag "comments_#{@post.id}" do %>
<%= render "comments/comments", comments: @comments %>
<% end %>
6 changes: 1 addition & 5 deletions app/views/comments/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<%= turbo_frame_tag "new_comment_#{@post.id}" do %>
<article class="media pt-2" style="border-style:solid;border-color:#cdcdcd;border-width:0.1px 0px 0px;">
<figure class="media-left">
<p class="image is-48x48">
<%= render "members/thumb", member: current_member %>
</p>
</figure>
<%= render "shared/thumbnail", member: current_member %>
<div class="media-content">
<%= render "comments/form", url: member_post_comments_path(@post.author, @post), comment: @comment %>
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@
<%= link_to "Back", :back, class: "button is-primary" %>
</div>
<% end %>
<br /><br />
<div class='field is-grouped'>
<p class='subtitle has-text-link py-1 pr-5'>Unhappy?</p>
<%= link_to 'Cancel my account', registration_path(resource_name), data: { turbo_confirm: 'Are you sure?', turbo_method: :delete }, class:'button is-danger' %>
</div>
12 changes: 7 additions & 5 deletions app/views/posts/_icon_comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<span>
<a data-controller="stimulus" data-stimulus-post-value=<%= post.id %> >
<i id=<%= "comment_icon_#{post.id}" %> data-action="click->stimulus#toggle_comments" class="fa-regular fa-comments"></i>
</a>
<span> </span>
<span id=<%= "comments_counter_#{post.id}" %> ><%= post.comments_counter %></span>
<%= link_to member_post_comments_path(post.author_id, post),
data: {
turbo_frame: "comments_#{post.id}"
} do %>
<i id=<%= "comment_icon_#{post.id}" %> class="fa-regular fa-comments"></i>
<% end %>
<span id=<%= "comments_counter_#{post.id}" %> > <%= post.comments_counter %></span>
</span>
3 changes: 1 addition & 2 deletions app/views/posts/_icon_likes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
<a data-controller="stimulus" data-stimulus-member-value=<%= current_member.id %> data-stimulus-post-value=<%= post.id %> >
<i id=<%= "like_icon_#{post.id}" %> data-action="click->stimulus#toggle_likes" class="<%= "#{icon}" %> fa-thumbs-up"></i>
</a>
<span> </span>
<span id=<%= "likes_counter_#{post.id}" %> ><%= post.likes_counter %></span>
<span id=<%= "likes_counter_#{post.id}" %> > <%= post.likes_counter %></span>
</span>
14 changes: 2 additions & 12 deletions app/views/posts/_post.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<%= turbo_frame_tag post do %>
<article class="media pt-2" style="border-style:solid;border-color:#cdcdcd;border-width:0.1px 0px 0px;">
<figure class="media-left">
<p class="image is-48x48">
<%= render "members/thumb", member: post.author %>
</p>
</figure>
<%= render "shared/thumbnail", member: post.author %>
<div class="media-content">
<div class="content">
<p>
Expand All @@ -17,13 +13,7 @@
<small><%= render "icon_new", post: post %> · <%= render "icon_comments", post: post %> · <%= render "icon_likes", post: post %> · <%= "#{distance_of_time_in_words_to_now(post.updated_at)} ago" %><%= render "post_update", post: post %></small>
</p>
</div>
<div id=<%= "comments_#{post.id}" %> class="hidden_comments">
<%= turbo_frame_tag "comments_#{post.id}" do %>
<% post.comments.includes(:author).each do |comment| %>
<%= render "comments/comment", comment: comment %>
<% end %>
<% end %>
</div>
<%= turbo_frame_tag "comments_#{post.id}" %>
</div>
</article>

Expand Down
4 changes: 1 addition & 3 deletions app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<div class='navbar-brand' data-controller='stimulus'>
<% if member_signed_in? %>
<%= link_to root_path, class: 'p-3' do %>
<figure class='image is-48x48'>
<%= render 'members/thumb', member: current_member %>
</figure>
<%= render 'shared/thumbnail', member: current_member %>
<% end %>
<div class="navbar-item has-text-warning-dark">
<%= current_member.email %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/shared/_thumbnail.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<figure class="media-left">
<p class="image is-48x48">
<%= render "members/thumb", member: member %>
</p>
</figure>

0 comments on commit d1fc391

Please sign in to comment.