Skip to content

Commit

Permalink
fix: simplemde initialization for forum thread form
Browse files Browse the repository at this point in the history
  • Loading branch information
Waishnav committed Jul 28, 2024
1 parent 2f669a9 commit e042dc4
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 101 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/simple_discussion/application.js

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions app/assets/javascripts/simple_discussion/controllers/index.js

This file was deleted.

This file was deleted.

This file was deleted.

39 changes: 39 additions & 0 deletions app/views/layouts/simple_discussion.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,44 @@
})
}
})

Stimulus.register("simplemde", class extends Controller {
static targets = ["textarea"]

connect() {
this.initializeEditor();

const previewButton = document.querySelector(".preview")
previewButton.style.width = "80px"
previewButton.style.height = "34px"
}

initializeEditor() {
this.editor = new SimpleMDE({
element: this.textareaTarget,
forceSync: true,
toolbar: [
"bold",
"italic",
"heading",
"|",
"quote",
"unordered-list",
"ordered-list",
"|",
"link",
{
name: "preview",
className: "preview no-disable",
action: function(editor) {
SimpleMDE.togglePreview(editor);
},
title: "Preview",
}
],
spellChecker: false,
});
}
})
</script>

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<%= icon("fas","ellipsis-v") %>
</button>
<div class="dropdown-menu dropdown-menu-right" data-dropdown-target="dropdownMenu">
<%= link_to t('report_spam'), "#", class: "dropdown-item", data: { controller: "report-spam", report_spam_target: "reportSpamButton", toggle: "modal", target: "#reportSpamModal", post_id: forum_post.id } %>
<% if is_moderator_or_owner?(forum_post) %>
<%= link_to t('edit_post'), simple_discussion.edit_forum_thread_forum_post_path(@forum_thread, forum_post),
class: "dropdown-item",
Expand Down
4 changes: 2 additions & 2 deletions app/views/simple_discussion/forum_threads/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= form_for @forum_thread,
url: (@forum_thread.persisted? ? simple_discussion.forum_thread_path(@forum_thread) : simple_discussion.forum_threads_path),
html: { data: {behavior: "comment-form"} } do |f| %>
html: { data: { behavior: "comment-form", controller: "simplemde" } } do |f| %>

<% if @forum_thread.errors.any? %>
<div class="alert alert-danger" role="alert">
Expand All @@ -24,7 +24,7 @@
<%= f.fields_for :forum_posts do |p| %>
<div class="form-group">
<%= p.label :body, t('what_help_needed') %>
<%= p.text_area :body, placeholder: t('add_a_comment'), rows: 10, class: "form-control simplemde", data: { behavior: "comment-body" } %>
<%= p.text_area :body, placeholder: t('add_a_comment'), rows: 10, class: "form-control simplemde", data: { behavior: "comment-body", simplemde_target: "textarea" } %>
</div>
<% end %>
<% end %>
Expand Down

0 comments on commit e042dc4

Please sign in to comment.