The project advance
This commit is contained in:
parent
ffbfe2ddd0
commit
8bce7d33ca
@ -31,7 +31,6 @@ class ChatConsumer(WebsocketConsumer):
|
||||
|
||||
self.send(text_data=json.dumps({
|
||||
'type':'chat',
|
||||
'username':self.scope["user"].pk,
|
||||
'username':self.scope["user"].username,
|
||||
'message':message
|
||||
}))
|
||||
|
||||
|
@ -10,6 +10,8 @@ import RegisterView from "./views/accounts/RegisterView.js";
|
||||
|
||||
let client = new Client(location.protocol + "//" + location.host)
|
||||
|
||||
let lastView = undefined
|
||||
|
||||
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
|
||||
|
||||
const getParams = match => {
|
||||
@ -54,7 +56,10 @@ const router = async () => {
|
||||
};
|
||||
}
|
||||
|
||||
if (lastView !== undefined)
|
||||
await lastView.leavePage();
|
||||
const view = new match.route.view(getParams(match));
|
||||
lastView = view;
|
||||
|
||||
document.querySelector("#app").innerHTML = await view.getHtml();
|
||||
|
||||
|
@ -6,6 +6,9 @@ export default class {
|
||||
async postInit() {
|
||||
}
|
||||
|
||||
async leavePage() {
|
||||
}
|
||||
|
||||
setTitle(title) {
|
||||
document.title = title;
|
||||
}
|
||||
|
@ -36,6 +36,10 @@ export default class extends AbstractView {
|
||||
|
||||
}
|
||||
|
||||
async leavePage() {
|
||||
this.chatSocket.close();
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
return `
|
||||
<h1>Chat</h1>
|
||||
|
@ -6,5 +6,5 @@ djangorestframework==3.14.0
|
||||
install==1.3.5
|
||||
pytz==2023.3.post1
|
||||
sqlparse==0.4.4
|
||||
channels==3.0.5
|
||||
channels==4.0.0
|
||||
daphne
|
||||
|
Loading…
Reference in New Issue
Block a user