From 520bead27f88bcefabe4ab9167eb27236488e06f Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 16 Dec 2024 16:59:31 -0600 Subject: [PATCH 1/5] Open the title field for editing after creating a new bubble --- app/assets/stylesheets/bubbles.css | 5 +++++ app/controllers/bubbles_controller.rb | 2 +- app/views/bubbles/_bubble.html.erb | 14 +++++++++----- app/views/bubbles/show.html.erb | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/bubbles.css b/app/assets/stylesheets/bubbles.css index 25b014300..608a8d2da 100644 --- a/app/assets/stylesheets/bubbles.css +++ b/app/assets/stylesheets/bubbles.css @@ -330,6 +330,11 @@ color: var(--splat-color); } + textarea::selection { + background-color: var(--bubble-color); + color: var(--color-ink-reversed); + } + @media (hover: hover) { .bubble:has(.bubble__image img:not([src=""])):hover & { color: var(--color-ink-reversed); diff --git a/app/controllers/bubbles_controller.rb b/app/controllers/bubbles_controller.rb index 2c8cf0be5..974c9aec9 100644 --- a/app/controllers/bubbles_controller.rb +++ b/app/controllers/bubbles_controller.rb @@ -12,7 +12,7 @@ class BubblesController < ApplicationController def create @bubble = @bucket.bubbles.create! - redirect_to @bubble + redirect_to bucket_bubble_path(@bubble.bucket, @bubble, editing: true) end def show diff --git a/app/views/bubbles/_bubble.html.erb b/app/views/bubbles/_bubble.html.erb index 4945e02b6..033364ed5 100644 --- a/app/views/bubbles/_bubble.html.erb +++ b/app/views/bubbles/_bubble.html.erb @@ -6,12 +6,16 @@

- <%= turbo_frame_tag bubble, :edit do %> - <%= link_to bubble.title, edit_bucket_bubble_path(bubble.bucket, bubble), class: "txt-undecorated" %> + <% if local_assigns[:editing] %> + <%= turbo_frame_tag bubble, :edit, src: edit_bucket_bubble_path(bubble.bucket, bubble) %> + <% else %> + <%= turbo_frame_tag bubble, :edit do %> + <%= link_to bubble.title, edit_bucket_bubble_path(bubble.bucket, bubble), class: "txt-undecorated" %> -
- <%= render "bubbles/tags", bubble: bubble %> -
+
+ <%= render "bubbles/tags", bubble: bubble %> +
+ <% end %> <% end %>

diff --git a/app/views/bubbles/show.html.erb b/app/views/bubbles/show.html.erb index 959f5093b..7f0f2793e 100644 --- a/app/views/bubbles/show.html.erb +++ b/app/views/bubbles/show.html.erb @@ -61,7 +61,7 @@
- <%= render "bubbles/bubble", bubble: @bubble %> + <%= render "bubbles/bubble", bubble: @bubble, editing: params[:editing] %>
<%= render "bubbles/messages", bubble: @bubble %> From 4644fe43eeaca0dd24c9076e127606cdc4c7053c Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 16 Dec 2024 17:28:27 -0600 Subject: [PATCH 2/5] Wire up editing comments --- app/controllers/comments_controller.rb | 24 +++++++++++++++++++++++- app/views/comments/_comment.html.erb | 14 +------------- app/views/comments/edit.html.erb | 17 +++++++++++++++++ app/views/comments/show.html.erb | 22 ++++++++++++++++++++++ 4 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 app/views/comments/edit.html.erb create mode 100644 app/views/comments/show.html.erb 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 %> From bcc57d66dd9db56a44eba619391497c77e46c9e8 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 16 Dec 2024 17:29:07 -0600 Subject: [PATCH 3/5] Whitespace --- app/views/comments/edit.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb index 82ea427e6..2df0f1e16 100644 --- a/app/views/comments/edit.html.erb +++ b/app/views/comments/edit.html.erb @@ -1,6 +1,7 @@ <%= 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_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 %> From 33d2d098f18f06d107f717f715fe5ce9796aeb02 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 16 Dec 2024 17:46:01 -0600 Subject: [PATCH 4/5] Wire up comment deletion --- app/controllers/comments_controller.rb | 7 ++++++- app/models/concerns/messageable.rb | 2 +- app/views/comments/edit.html.erb | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1746763b4..ab1404cfb 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,6 +1,6 @@ class CommentsController < ApplicationController include BubbleScoped, BucketScoped - before_action :set_comment, only: [ :show, :edit, :update ] + before_action :set_comment, only: [ :show, :edit, :update, :destroy ] def create @bubble.capture new_comment @@ -18,6 +18,11 @@ class CommentsController < ApplicationController render :show end + def destroy + @comment.destroy + redirect_to @bubble + end + private def comment_params params.require(:comment).permit(:body) diff --git a/app/models/concerns/messageable.rb b/app/models/concerns/messageable.rb index 1005f5492..723be91d2 100644 --- a/app/models/concerns/messageable.rb +++ b/app/models/concerns/messageable.rb @@ -4,7 +4,7 @@ module Messageable TYPES = %w[ Comment EventSummary ] included do - has_one :message, as: :messageable, touch: true + has_one :message, as: :messageable, touch: true, dependent: :destroy has_one :bubble, through: :message end end diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb index 2df0f1e16..a4ecf07df 100644 --- a/app/views/comments/edit.html.erb +++ b/app/views/comments/edit.html.erb @@ -4,7 +4,7 @@ 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 %> + <%= form.button class: "btn btn--reversed txt-small", type: :submit do %> <%= image_tag "check.svg", aria: { hidden: true }, size: 16 %> Save <% end %> @@ -12,7 +12,15 @@ <%= image_tag "close.svg", aria: { hidden: true }, size: 16 %> Cancel <% end %> + + <%= tag.button type: :submit, class: "btn btn--small btn--negative flex-item-justify-end", form: dom_id(@comment, :delete_form), + data: { turbo_confirm: "Are you sure you want to delete this comment?" } do %> + <%= image_tag "remove.svg", aria: { hidden: true }, size: 16 %> + Delete + <% end %>
<% end %> + + <%= form_with url: bucket_bubble_comment_path(@bubble.bucket, @bubble, @comment), method: :delete, id: dom_id(@comment, :delete_form), data: { turbo_frame: "_top" } %>
<% end %> From 1eb40a318b0dd7b25d872ee226309420e913203e Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Mon, 16 Dec 2024 17:49:21 -0600 Subject: [PATCH 5/5] Update test --- test/controllers/bubbles_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/controllers/bubbles_controller_test.rb b/test/controllers/bubbles_controller_test.rb index 6cc00f10d..4f1d0733e 100644 --- a/test/controllers/bubbles_controller_test.rb +++ b/test/controllers/bubbles_controller_test.rb @@ -19,7 +19,7 @@ class BubblesControllerTest < ActionDispatch::IntegrationTest assert_difference "Bubble.count", 1 do post bucket_bubbles_url(buckets(:writebook)) end - assert_redirected_to bucket_bubble_url(buckets(:writebook), Bubble.last) + assert_redirected_to bucket_bubble_url(buckets(:writebook), Bubble.last, editing: true) end test "show" do