diff --git a/chat/__init__.py b/chat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chat/admin.py b/chat/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/chat/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/chat/apps.py b/chat/apps.py new file mode 100644 index 0000000..2fe899a --- /dev/null +++ b/chat/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ChatConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'chat' diff --git a/chat/models.py b/chat/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/chat/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/chat/tests.py b/chat/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/chat/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/chat/views.py b/chat/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/chat/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/frontend/consumers.py b/frontend/consumers.py new file mode 100644 index 0000000..976eb9f --- /dev/null +++ b/frontend/consumers.py @@ -0,0 +1,10 @@ +import json +from channels.generic.websocket import WebsocketConsumer + +class ChatConsumer(WebsocketConsumer): + def connect(self): + self.accept() + self.send(text_data=json.dumps({ + 'type':'connection_established', + 'message':'You are now connected!' + })) diff --git a/frontend/routing.py b/frontend/routing.py new file mode 100644 index 0000000..25c7331 --- /dev/null +++ b/frontend/routing.py @@ -0,0 +1,6 @@ +from django.urls import re_path +from . import consumers + +websocket_urlpatterns = [ + re_path(r'ws/socket_server/', consumers.ChatConsumer.as_asgi()) +] diff --git a/frontend/static/css/index.css b/frontend/static/css/index.css index 9416823..db15e14 100644 --- a/frontend/static/css/index.css +++ b/frontend/static/css/index.css @@ -1,37 +1,9 @@ body { - --nav-width: 200px; - margin: 0 0 0 var(--nav-width); + margin: 10; font-family: 'Quicksand', sans-serif; font-size: 18px; } -.nav { - position: fixed; - top: 0; - left: 0; - width: var(--nav-width); - height: 100vh; - background: #222222; -} - -.nav__link { - display: block; - padding: 12px 18px; - text-decoration: none; - color: #eeeeee; - font-weight: 500; -} - -.nav__link:hover { - background: rgba(255, 255, 255, 0.05); -} - -#app { - margin: 2em; - line-height: 1.5; - font-weight: 500; -} - a { color: #009579; -} \ No newline at end of file +} diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js index f63c27c..45051dc 100644 --- a/frontend/static/js/index.js +++ b/frontend/static/js/index.js @@ -2,6 +2,7 @@ import Dashboard from "./views/Dashboard.js"; import Posts from "./views/Posts.js"; import PostView from "./views/PostView.js"; import Settings from "./views/Settings.js"; +import Chat from "./views/Chat.js"; const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$"); @@ -24,7 +25,8 @@ const router = async () => { { path: "/", view: Dashboard }, { path: "/posts", view: Posts }, { path: "/posts/:id", view: PostView }, - { path: "/settings", view: Settings } + { path: "/settings", view: Settings }, + { path: "/chat", view: Chat }, ]; // Test each route for potential match @@ -60,4 +62,4 @@ document.addEventListener("DOMContentLoaded", () => { }); router(); -}); \ No newline at end of file +}); diff --git a/frontend/static/js/views/Chat.js b/frontend/static/js/views/Chat.js new file mode 100644 index 0000000..46a9f40 --- /dev/null +++ b/frontend/static/js/views/Chat.js @@ -0,0 +1,21 @@ +import AbstractView from "./AbstractView.js"; + +export default class extends AbstractView { + constructor(params) { + super(params); + this.setTitle("Chat"); + let url = `ws://${window.location.host}/ws/socket-server/` + + const chatSocket = new WebSocket(url) + chatSocket.onmessage = function(e) { + let data = JSON.parse(e.data) + console.log('Data:', data) + } + } + + async getHtml() { + return ` +