|
| 1 | +<div id="<%= dom_id(comment) %>" class="my-5 flex <%= current_user == comment.user ? 'justify-start' : 'justify-end' %>"> |
| 2 | + <div class="w-3/4"> |
| 3 | + <!-- Name and date outside the bubble --> |
| 4 | + <div class="flex justify-between items-center mb-1"> |
| 5 | + <p class="text-xs text-gray-500 <%= current_user != comment.user ? 'text-right' : '' %>"> |
| 6 | + <span class="font-semibold"><%= comment.user.email %></span> |
| 7 | + | <%= comment.created_at.strftime("%B %d, %Y at %I:%M %p") %> |
| 8 | + <% if comment.updated_at != comment.created_at %> |
| 9 | + (edited <%= time_ago_in_words(comment.updated_at) %> ago) |
| 10 | + <% end %> |
| 11 | + </p> |
| 12 | + <% if current_user && (current_user == comment.user || current_user.admin?) %> |
| 13 | + <div class="flex space-x-2"> |
| 14 | + <button onclick="toggleEditComment('<%= dom_id(comment) %>')" class="text-xs text-sky-600 hover:text-sky-800"> |
| 15 | + Edit |
| 16 | + </button> |
| 17 | + <%= link_to "Delete", document_comment_path(@document, comment), |
| 18 | + data: { |
| 19 | + turbo_method: :delete, |
| 20 | + turbo_confirm: "Are you sure you want to delete this comment?" |
| 21 | + }, |
| 22 | + class: "text-xs text-red-600 hover:text-red-800" %> |
| 23 | + </div> |
| 24 | + <% end %> |
| 25 | + </div> |
| 26 | + |
| 27 | + <!-- Comment bubble --> |
| 28 | + <div class="comment-content"> |
| 29 | + <div class="p-4 rounded-bl-2xl rounded-br-2xl <%= current_user == comment.user ? 'rounded-tr-2xl' : 'rounded-tl-2xl' %> <%= current_user == comment.user ? 'bg-gray-100 text-stone-800' : 'bg-sky-100 text-sky-800' %> border <%= current_user == comment.user ? 'border-stone-200' : 'border-sky-300' %> shadow-sm"> |
| 30 | + <p class="leading-relaxed"><%= simple_format(comment.content) %></p> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + |
| 34 | + <!-- Edit form --> |
| 35 | + <% if current_user && (current_user == comment.user || current_user.admin?) %> |
| 36 | + <div class="comment-edit-form hidden mt-3"> |
| 37 | + <div class="p-4 rounded-bl-2xl rounded-br-2xl <%= current_user == comment.user ? 'rounded-tr-2xl' : 'rounded-tl-2xl' %> bg-gray-50 border border-gray-200 shadow-sm"> |
| 38 | + <%= form_with model: [@document, comment], local: true, class: "space-y-3" do |form| %> |
| 39 | + <%= form.text_area :content, rows: 3, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-sky-500 focus:border-transparent resize-vertical" %> |
| 40 | + <div class="flex space-x-2"> |
| 41 | + <%= form.submit "Update Comment", class: "px-4 py-2 bg-sky-600 text-white rounded-md hover:bg-sky-700 focus:outline-none focus:ring-2 focus:ring-sky-500" %> |
| 42 | + <button type="button" onclick="toggleEditComment('<%= dom_id(comment) %>')" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-md hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-500"> |
| 43 | + Cancel |
| 44 | + </button> |
| 45 | + </div> |
| 46 | + <% end %> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + <% end %> |
| 50 | + </div> |
| 51 | +</div> |
0 commit comments