Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gsoc'24): minimal markdown editor using simplemde #26

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d248490
added the profanity, hate, violance, sex filter using `language_filte…
Waishnav Jun 17, 2024
3962dc3
added js for dropdown, and for markdown editor in future
Waishnav Jun 23, 2024
0793d17
ui: dropdown for delete, edit, mark as solution actions
Waishnav Jun 23, 2024
0441419
feat: user can now report the forum post as spam
Waishnav Jun 25, 2024
9d93c57
feat: moderator can review and delete reported posts
Waishnav Jun 25, 2024
4168fc0
fix standardrb formatting issue
Waishnav Jul 25, 2024
5012477
fix: renaming report_spam button to report_post
Waishnav Jul 27, 2024
ce14ec1
fix: remove js bundeling
Waishnav Jul 28, 2024
3ac6ab0
fix: ci fail due to old schema in test dummy
Waishnav Jul 28, 2024
2446edc
fix: ci fail due to migration version
Waishnav Jul 28, 2024
99e9d8d
removing stimulus controller
Waishnav Jul 28, 2024
0788044
added the profanity, hate, violance, sex filter using `language_filte…
Waishnav Jun 17, 2024
cfc7f83
added js for dropdown, and for markdown editor in future
Waishnav Jun 23, 2024
909a6f1
feat: user can now report the forum post as spam
Waishnav Jun 25, 2024
99d7ab5
feat: adding markdown editor using simplemde
Waishnav Jul 7, 2024
07c23ef
fix: simplemde initialization for forum thread form
Waishnav Jul 22, 2024
82b5c4b
updated schema
Waishnav Aug 20, 2024
a33cf37
removed report spam modal | something went wrong with rebase
Waishnav Aug 20, 2024
92bacbb
removed package.json
Waishnav Aug 20, 2024
75770fd
removed the unnecsarry comment
Waishnav Aug 22, 2024
08c2bdf
fix: removed the body of forum thread since it is markdown now
Waishnav Aug 23, 2024
4878c94
fix: global css problem
Waishnav Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/assets/stylesheets/simple_discussion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,25 @@
.thread-page-container {
padding: 24px;
}

.preview::before {
content: "Preview";
width: 80px;
}

p {
font-size: 18px;
}
Waishnav marked this conversation as resolved.
Show resolved Hide resolved

blockquote {
border-left: 5px solid #e9ecef;
padding: 10px 20px;
margin: 10px 0;
font-size: 18px;
font-weight: 500;
color: #6c757d;
}

.CodeMirror-line span {
font-size: 18px;
}
44 changes: 43 additions & 1 deletion app/views/layouts/simple_discussion.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@

<% parent_layout("application") %>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>

<script type="module">
import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
window.Stimulus = Application.start()
Expand All @@ -99,7 +102,6 @@
}
})


Stimulus.register("report-post", class extends Controller {
static targets = ["reportPostButton"]

Expand All @@ -117,4 +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>

8 changes: 2 additions & 6 deletions app/views/simple_discussion/forum_posts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="mt-4"></div>
<%= form_for [@forum_thread, @forum_post],
url: (@forum_post.persisted? ? simple_discussion.forum_thread_forum_post_path(@forum_thread, @forum_post) : simple_discussion.forum_thread_forum_posts_path(@forum_thread)),
html: { data: { behavior: "comment-form" } } do |f| %>
html: { data: { behavior: "comment-form", controller: "simplemde" } } do |f| %>

<% if @forum_post.errors.any? %>
<div class="alert alert-danger" role="alert">
Expand All @@ -13,12 +13,8 @@

<div class="d-block position-relative">
<div class="form-group">
<%= f.text_area :body, placeholder: t('add_a_comment'), rows: 8, class: "form-control simplemde", data: { behavior: "comment-body" } %>
<%= f.text_area :body, placeholder: t('add_a_comment'), rows: 8, class: "form-control", data: { behavior: "comment-body", simplemde_target: "textarea"} %>
</div>
<%= f.button "#{f.object.new_record? ? t('comment') : t('update_comment') }", class: "btn forum-primary-btn", style: "bottom: 10px; right: 10px", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> #{t('saving_comment')}"} %>
</div>

<%# Describe text formatting options here with a link %>
<%#= link_to "Parsed with Markdown", "https://guides.github.com/features/mastering-markdown/", target: "_blank" %>

<% end %>
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
1 change: 1 addition & 0 deletions app/views/simple_discussion/forum_threads/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</div>
</div>


<div class="d-flex mb-4">
<div class="thread-details-custom">
<%= t("created_by") %> <%= @forum_thread.user.name %> • <%= time_ago_in_words(@forum_thread.created_at) %> <%= t("ago") %>
Expand Down