diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f31eeb388..1746763b4 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,13 +1,35 @@ class CommentsController < ApplicationController include BubbleScoped, BucketScoped + before_action :set_comment, only: [ :show, :edit, :update ] def create @bubble.capture new_comment redirect_to @bubble end + def show + end + + def edit + end + + def update + @comment.update! comment_params + render :show + end + private + def comment_params + params.require(:comment).permit(:body) + end + def new_comment - Comment.new params.expect(comment: [ :body ]) + Comment.new(comment_params) + end + + def set_comment + @comment = Comment.joins(:message) + .where(messages: { bubble_id: @bubble.id }) + .find(params[:id]) end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index d405d8bc8..878fdd9f4 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -3,17 +3,5 @@ <%= avatar_tag comment.creator, loading: :lazy %> -
-
- <%= comment.creator.name %> - <%= link_to bucket_bubble_path(comment.bubble.bucket, comment.bubble, anchor: "comment_#{comment.id}"), class: "txt-undecorated" do %> - <%= tag.time comment.created_at, class: "comment__timestamp" do %> - <%= comment.created_at.strftime("%b %d") %> - <% end %> - <% end %> -
-
- <%= simple_format comment.body %> -
-
+ <%= turbo_frame_tag dom_id(comment), src: bucket_bubble_comment_path(comment.bubble.bucket, comment.bubble, comment) %> <% end %> diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb new file mode 100644 index 000000000..82ea427e6 --- /dev/null +++ b/app/views/comments/edit.html.erb @@ -0,0 +1,17 @@ +<%= turbo_frame_tag dom_id(@comment) do %> +
+ <%= form_with model: [@bubble.bucket, @bubble, @comment], class: "flex flex-column gap full-width", data: { controller: "form", action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel" } do |form| %> + <%= form.text_area :body, class: "input comment__input", required: true, rows: 3 %> +
+ <%= form.button class: "btn btn--reversed txt-small" do %> + <%= image_tag "check.svg", aria: { hidden: true }, size: 16 %> + Save + <% end %> + <%= link_to bucket_bubble_comment_path(@bubble.bucket, @bubble, @comment), class: "btn btn--small", data: { form_target: "cancel" } do %> + <%= image_tag "close.svg", aria: { hidden: true }, size: 16 %> + Cancel + <% end %> +
+ <% end %> +
+<% end %> diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb new file mode 100644 index 000000000..94f7362af --- /dev/null +++ b/app/views/comments/show.html.erb @@ -0,0 +1,22 @@ +<%= turbo_frame_tag dom_id(@comment) do %> +
+
+ <%= @comment.creator.name %> + <%= link_to bucket_bubble_path(@comment.bubble.bucket, @comment.bubble, anchor: "comment_#{@comment.id}"), class: "txt-undecorated" do %> + <%= tag.time @comment.created_at, class: "comment__timestamp" do %> + <%= @comment.created_at.strftime("%b %d") %> + <% end %> + <% end %> + + <% if @comment.creator == Current.user %> + <%= link_to edit_bucket_bubble_comment_path(@comment.bubble.bucket, @comment.bubble, @comment), class: "btn txt-small btn--plain", style: "font-size: 0.4em; opacity: 0.5;" do %> + <%= image_tag "menu-dots-horizontal.svg", class: "icon" %> + Edit + <% end %> + <% end %> +
+
+ <%= simple_format @comment.body %> +
+
+<% end %>