-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from shazam442/comment-editing
Comment editing
- Loading branch information
Showing
10 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
import "trix" | ||
import "@rails/actiontext" | ||
import "controllers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Application } from "@hotwired/stimulus" | ||
|
||
const application = Application.start() | ||
|
||
// Configure Stimulus development experience | ||
application.debug = false | ||
window.Stimulus = application | ||
|
||
export { application } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
initialize() {} | ||
|
||
connect() {} | ||
|
||
toggleForm(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
const formID = event.params["form"] | ||
const bodyID = event.params["body"] | ||
|
||
const formElement = document.getElementById(formID) | ||
const bodyElement = document.getElementById(bodyID) | ||
|
||
formElement.classList.toggle("d-none") | ||
bodyElement.classList.toggle("d-none") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
connect() { | ||
this.element.textContent = "Hello World!" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Import and register all your controllers from the importmap via controllers/**/*_controller | ||
import { application } from "controllers/application" | ||
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" | ||
eagerLoadControllersFrom("controllers", application) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
<div class="container comment-<%= comment.id %>" | ||
style="border: 1px solid black; padding: 1em; margin: 1em"> | ||
<%= comment.user.email %><br> | ||
<span>Posted <%= time_ago_in_words(comment.created_at) %> ago</span> | ||
<% if (comment.updated_at - comment.created_at) > 1 %> | ||
<span>Edited <%= time_ago_in_words(comment.updated_at) %> ago</span> | ||
<% else %> | ||
<span>Posted <%= time_ago_in_words(comment.created_at) %> ago</span> | ||
<% end %> | ||
<% if current_user == comment.user %> | ||
<div class="button-group float-end"> | ||
<div class="btn-group float-end"> | ||
<%= link_to "Edit", nil, remote: true, class: "btn btn-warning", | ||
data: { | ||
controller: "comments", | ||
action: "comments#toggleForm", | ||
comments_form_param: "edit-form-#{comment.id}", | ||
comments_body_param: "comment-body-#{comment.id}" | ||
} %> | ||
<%= button_to "Delete", [post, comment], class: "btn btn-danger", method: :delete %> | ||
</div> | ||
<div id="edit-form-<%= comment.id %>" class="d-none mt-5" > | ||
<%= render "comments/form", | ||
post: post, | ||
comment: comment, | ||
submit_label: "Update" %> | ||
</div> | ||
<% end %> | ||
<hr> | ||
<%= comment.body %> | ||
<div id="comment-body-<%= comment.id %>"> | ||
<%= comment.body %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<%= form_with(model: [post, post.comments.build]) do |f| %> | ||
<%= form_with(model: [post, comment]) do |f| %> | ||
<div class="form-control"> | ||
<%= f.label :body %> | ||
<%= f.rich_text_area :body %> | ||
<%= f.submit "Reply", class: "btn btn-primary mt-1" %> | ||
<%= f.submit submit_label, class: "btn btn-primary mt-1" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters