Skip to content

Commit

Permalink
Lots of changes. Add JavaScript tests for the comment_form.js module.
Browse files Browse the repository at this point in the history
  • Loading branch information
danirus committed Feb 1, 2022
1 parent bed3d07 commit 3618f6b
Show file tree
Hide file tree
Showing 40 changed files with 1,579 additions and 709 deletions.
13 changes: 11 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-transform-runtime"]
],

"env": {
"test": {
"plugins": ["transform-es2015-modules-commonjs"]
}
}
}
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# https://editorconfig.org/

root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8

# Docstrings and comments use max_line_length = 79
[*.py]
max_line_length = 80

# Use 2 spaces for the HTML files
[*.html]
indent_size = 2

# The JSON files contain newlines inconsistently
[*.json]
indent_size = 2
insert_final_newline = ignore

# Minified JavaScript files shouldn't be changed
[**.min.js]
indent_style = ignore
insert_final_newline = ignore

# Makefiles always use tabs for indentation
[Makefile]
indent_style = tab

[docs/**.rst]
max_line_length = 79

[*.yml]
indent_size = 2
10 changes: 10 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/*.min.js
django_comments_xtd/static/django_comments_xtd/dist/*
docs/_build/**/*.js
node_modules/**.js
js_tests/**/*.js
venv/**/*.js
demos/project-stories/psenv/**/*.js
webpack.config.js
**/webpack.config.js
Gruntfile.js
41 changes: 41 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"rules": {
"camelcase": ["off", {"properties": "always"}],
"comma-spacing": ["error", {"before": false, "after": true}],
"curly": ["error", "all"],
"dot-notation": ["error", {"allowKeywords": true}],
"eqeqeq": ["error"],
"indent": ["error", 4],
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
"linebreak-style": ["error", "unix"],
"new-cap": ["off", {"newIsCap": true, "capIsNew": true}],
"no-alert": ["off"],
"no-eval": ["error"],
"no-extend-native": ["error", {"exceptions": ["Date", "String"]}],
"no-multi-spaces": ["error"],
"no-octal-escape": ["error"],
"no-script-url": ["error"],
"no-shadow": ["error", {"hoist": "functions"}],
"no-underscore-dangle": ["error"],
"no-unused-vars": ["error", {"vars": "local", "args": "none"}],
"no-var": ["error"],
"prefer-const": ["error"],
"quotes": ["off", "single"],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
"space-infix-ops": ["error", {"int32Hint": false}],
"strict": ["error", "global"]
},
"env": {
"browser": true,
"es6": true
},
"globals": {
"django": false
}
}
18 changes: 9 additions & 9 deletions demo/project/users/static/users/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ let email_form = null;
let pdata_form = null;

window.addEventListener("DOMContentLoaded", (_) => {
if (document.getElementById("email_form")) {
email_form = new EmailForm('/user/account/edit/email',
'email_form', 'email_form_msg');
}
if (document.getElementById("email_form")) {
email_form = new EmailForm('/user/account/edit/email',
'email_form', 'email_form_msg');
}

if (document.getElementById("pdata_form")) {
pdata_form = new PersonalDataForm('/user/account/edit/pdata',
'pdata_form', 'pdata_form_msg');
}
if (document.getElementById("pdata_form")) {
pdata_form = new PersonalDataForm('/user/account/edit/pdata',
'pdata_form', 'pdata_form_msg');
}
});

window.submit_email_form = () => email_form ? email_form.post() : false;
window.submit_pdata_form = () => pdata_form ? pdata_form.post() : false;
window.submit_pdata_form = () => pdata_form ? pdata_form.post() : false;
84 changes: 0 additions & 84 deletions demos/project-stories/project_stories/templates/base.html.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
{% endif %}
{% if comment_reactions_enabled and is_input_allowed %}
<div>
<a data-type="reactions-panel" data-comment="{{ comment.id }}" class="small" data-user-auth="{{ user.is_authenticated }}" href="{% url 'comments-xtd-react' comment.id %}?{{ cpage_qs_param }}={{ page_obj.number }}" {% if not user.is_authenticated %}data-login-next="{% get_xtdcomment_permalink comment page_number %}{% endif %}">{% trans "React" %}</a>
<a data-dcx="reactions-panel" data-comment="{{ comment.id }}" class="small" data-user-auth="{{ user.is_authenticated }}" href="{% url 'comments-xtd-react' comment.id %}?{{ cpage_qs_param }}={{ page_obj.number }}" {% if not user.is_authenticated %}data-login-next="{% get_xtdcomment_permalink comment page_number %}{% endif %}">{% trans "React" %}</a>
</div>
{% endif %}
{% endif %}
{% if comment.level == 0 and comment.nested_count and not comment.is_removed %}
<div>
<span id="comment-{{ comment.id}}-replies" data-type="nreplies" data-comment="{{ comment.id }}" class="small">{% blocktrans count replies=comment.nested_count%}One reply{% plural %}{{ replies }} replies{% endblocktrans %}</span>
<span id="comment-{{ comment.id}}-replies" data-dcx="nreplies" data-comment="{{ comment.id }}" class="small">{% blocktrans count replies=comment.nested_count%}One reply{% plural %}{{ replies }} replies{% endblocktrans %}</span>
</div>
{% endif %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h6 class="text-center pb24">
<div class="footer"></div>
</div>
</div>
<div class="not-reply-box l0"></div>
<div class="not-reply-box-img l0"></div>
{% else %}
{% with parent=form.reply_to.value|get_comment %}
<div class="comment-box-img l0-ini">
Expand Down
46 changes: 0 additions & 46 deletions demos/project-stories/project_stories/templates/homepage.html.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ <h4 class="text-center">{% trans "New comments are not allowed." %}</h4>

{% block extra_js %}
<script>
window.comments_api_props = {% get_comments_api_props for object %};
window.dcx = {}
</script>
<script type="module" src="{% static 'django_comments_xtd/js/comments.js' %}"></script>
<script type="module" src="{% static 'django_comments_xtd/js/reactions.js' %}"></script>
<script src="{% static 'django_comments_xtd/dist/dcx-3.0.0.js' %}"></script>
<div style="display: none">
{% render_comment_reply_template for object %}
</div>
Expand Down

This file was deleted.

Loading

8 comments on commit 3618f6b

@jdbit
Copy link

@jdbit jdbit commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, nice to see the new version is in active development! I just tried the 3.0.0 demo and it works, but ajax doesn't work (it's a work in progress I guess?). Based on the commit, it seems like the new ajax version will not require any dependencies like ReactJS or jQuery. Do you rewrite it in vanilla js?
Thank you for your work, I imagine how much time it takes to maintain the project!

@danirus
Copy link
Owner Author

@danirus danirus commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :-)
There is a demo project directory that should go away as it's outdated (demo/project), the two working projects are demos/project-quotes and demos/project-stories. The first doesn't use JavaScript, and the second does use the JavaScript code. Check that one. Everything works there. There are README.md files in both to set them up. What is missing yet is a battery of tests for the reply-forms.js and reactions.js module. The JavaScript tests added in this commit only test the comment-form.js module.
About the JavaScript plugin, yes, it's just Vanilla JavaScript. I develop a lot lately with TypeScript and React but I think django-comments-xtd should use a Vanilla approach by default, without any framework. Maybe it can be extended with a React plugin or whatnot with an external package.

@danirus
Copy link
Owner Author

@danirus danirus commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdbit, the README.md of demos/project-stories now explains how to load the fixtures and what users you can use to test the project.

@jdbit
Copy link

@jdbit jdbit commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your response! I just tried demos/project-stories, but it's still not ajax. The browser console says it can't find /static/django_comments_xtd/dist/dcx-3.0.0.js and it seems like this file doesn't exist anywhere in the project. Where can I find it?

@danirus
Copy link
Owner Author

@danirus danirus commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry for that. It has to be built.
I just added it. Thanks for telling :-)

@jdbit
Copy link

@jdbit jdbit commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, thank you, everything works now;) Just 4kb gzipped, I'm so glad you decided to make it vanilla js! The new default design is very nice too, however, I think these reply fields complicate the design and take too much space. Maybe it would be better to replace these inputs with just a link button near the React button (example here)? Just like threaded comments on Reddit. It's just a feedback, not trying to add you even more work:) Anyway, I'll try to make it on my own.
I think I can already use the new version in production. Can I migrate from the v.2.9 with existing comments in the db without losing the comments? It seems like you only added tables for reactions, the XtdComment model was untouched.

@danirus
Copy link
Owner Author

@danirus danirus commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback, I really appreciate it.
The problem with Reddit is that the reply dialog always displays immediately below the comment you click to reply.
So comments are ordered from more recent date to older ones, that's difficult to read. I mean, it's not in sequence.
Nevertheless I will keep it in mind.

You are brave if you want to use it in production, I guess it will work without problems, actually v3 has more tests than the previous versions. Indeed, the model XtdComment does not change, only the Reaction model and the related tables. But if you had Like/Dislike CommentFlags in your app, it won't work with Reactions. I have not done yet any migration command.

Thanks again a lot for your feedback :-)

@jdbit
Copy link

@jdbit jdbit commented on 3618f6b Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with Reddit is that the reply dialog always displays immediately below the comment you click to reply.

I see now.

You are brave if you want to use it in production

It's for my own small websites, so should not be a big issue if something goes wrong.
Thank you for your help and the great commenting app for Django!

Please sign in to comment.