Skip to content

Commit

Permalink
Some minor adjustments to the chat so that it works properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-s committed Nov 29, 2020
1 parent a0a7a28 commit 3523c88
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ dmypy.json
node_modules
/static
/core/static/dist
django-sockpuppet
.env/
42 changes: 42 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,45 @@
}
ASGI_APPLICATION = 'sockpuppet.routing.application'
WSGI_APPLICATION = 'app.wsgi.application'

logging_debug = 'DEBUG' if DEBUG else 'INFO'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'root': {
'handlers': ['console'],
'level': 'DEBUG'
},
'handlers': {
'console': {
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'sockpuppet': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
}
},
'formatters': {
'verbose': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'loggers': {
'django.db.backends': {
# uncomment to see all queries
# 'level': 'DEBUG',
'handlers': ['console'],
},
'sockpuppet': {
'level': logging_debug,
'handlers': ['sockpuppet']
}
}
}
2 changes: 1 addition & 1 deletion core/javascript/controllers/application_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class extends Controller {
}

beforeReflex (element, reflex) {
console.log("beforeReflex")
console.log("beforeReflex")
document
.querySelectorAll('[data-activity-indicator]')
.forEach(el => (el.hidden = false))
Expand Down
1 change: 1 addition & 0 deletions core/javascript/controllers/chat_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class extends ApplicationController {
}

reload (event) {
if (!event.detail) return
const { messageId } = event.detail
if (messageId === lastMessageId) return
debouncedReload(this)
Expand Down
6 changes: 3 additions & 3 deletions core/reflexes/chat_reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def post(self, color, message, message_id):
chats = cache.get("chats", [])
chats.append({
'message': message,
'message_id': message_id,
'messageId': message_id,
'created_at': timezone.now()
})
cache.set("chats", chats)
channel = Channel("chat")
channel = Channel("ChatChannel")
channel.dispatch_event({
'name': 'chats:added',
'detail': {'messagre_id': message_id}
'detail': {'messageId': message_id}
})
channel.broadcast()
2 changes: 0 additions & 2 deletions core/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ footer {
footer,
header,
main {
margin: 0 auto;
max-width: var(--width-content);
padding: 0rem 2rem;
}

Expand Down
10 changes: 6 additions & 4 deletions core/templates/_chat_demo.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

<article id="red"
data-controller="chat"
data-action="chats:added@document->chat#reload cable-ready:after-morph@document->chat#scroll">
<span data-target="chat.list">
data-controller="chat"
data-action="chats:added@document->chat#reload cable-ready:after-morph@document->chat#scroll"
data-reflex-root="#chat-container"
>
<span id="chat-container" data-target="chat.list">
{% for chat in chats %}
<aside class="message" style="min-height:auto; margin-top: 15px;">
<p>
{{chat.message}} <sup>{{chat.created_at|timesince}} ago </sup>
{{ chat.message }} <sup>{{ chat.created_at|timesince }} ago </sup>
</p>
</aside>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2> {% block subtitle %}Django Sockpuppet{% endblock subtitle %}</h2>
<a href="https://github.com/zodman/django-sockpuppet-expo">
<img src="https://img.shields.io/static/v1?label=github&message=django-sockpuppet-expo&logo=github">
</a>
<a href="https://github.com/zodman/django-socketpuppet-expo">
<a href="https://github.com/zodman/django-socketpuppet-expo">
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/zodman/django-socketpuppet-expo?style=social">
</a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"@rails/ujs@^6.0.3-4":
version "6.0.3-4"
resolved "https://nexus.gcds.coke.com/repository/npm-group/@rails/ujs/-/ujs-6.0.3-4.tgz#8dafc84178080f9c4f21076953ea1d0dc0bfe0fc"
resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.0.3-4.tgz#8dafc84178080f9c4f21076953ea1d0dc0bfe0fc"
integrity sha512-pNEEndJYNMCYEZG79MkoMc40AYKBfm0md8pawJ/SUu/1aIhToJcKu+9hHT/7WMLudsakOgC/C8KKFuZOs4QTgw==

"@stimulus/core@^1.1.1":
Expand Down

0 comments on commit 3523c88

Please sign in to comment.