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/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f31eeb388..ab1404cfb 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,13 +1,40 @@ class CommentsController < ApplicationController include BubbleScoped, BucketScoped + before_action :set_comment, only: [ :show, :edit, :update, :destroy ] 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 + + def destroy + @comment.destroy + redirect_to @bubble + 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/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/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 %> diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 98c37b6cb..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 %> -
-
- <%= sanitize comment.body_html %> -
-
+ <%= 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..a4ecf07df --- /dev/null +++ b/app/views/comments/edit.html.erb @@ -0,0 +1,26 @@ +<%= 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", type: :submit 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 %> + + <%= 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 %> 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 %> 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