Added new views.
This commit is contained in:
parent
659c30f376
commit
71d967114d
97
src/snek/templates/new.html
Normal file
97
src/snek/templates/new.html
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, interactive-widget=resizes-content">
|
||||||
|
<link rel="manifest" href="/manifest.json" />
|
||||||
|
<style>
|
||||||
|
body{
|
||||||
|
background-color: black;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="module">
|
||||||
|
import { Socket } from "./socket.js";
|
||||||
|
|
||||||
|
class ChatWindow extends HTMLElement {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.component = document.createElement("div");
|
||||||
|
this.message_list = document.createElement("div")
|
||||||
|
this.component.appendChild(this.message_list);
|
||||||
|
this.chat_input = document.createElement("div")
|
||||||
|
this.component.appendChild(this.chat_input);
|
||||||
|
this.channelUid = null
|
||||||
|
this.channelUid = this.getAttribute("channel")
|
||||||
|
this.inputText = document.createElement("textarea")
|
||||||
|
this.inputText.addEventListener("keyup",(e)=>{
|
||||||
|
|
||||||
|
|
||||||
|
this.rpc.sendMessage(this.channelUid, e.target.value,false)
|
||||||
|
if(e.key == "Enter" && !e.shiftKey){
|
||||||
|
|
||||||
|
|
||||||
|
this.rpc.sendMessage(this.channelUid, e.target.value,true)
|
||||||
|
|
||||||
|
e.target.value = ""
|
||||||
|
}else{
|
||||||
|
//this.rpc.sendMessage(this.channelUid, e.target.value, false)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.component.appendChild(this.inputText)
|
||||||
|
this.ws = new Socket();
|
||||||
|
this.ws.addEventListener("channel-message", this.handleMessage.bind(this))
|
||||||
|
this.rpc = this.ws.client
|
||||||
|
this.ws.addEventListener("update_message_text",this.handleMessage.bind(this))
|
||||||
|
window.chat = this
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMessage(data,data2) {
|
||||||
|
if(data2 && data2.event)
|
||||||
|
data = data.data
|
||||||
|
console.info(["update-messagettt",data])
|
||||||
|
console.warn(data.uid)
|
||||||
|
if(!data.html)
|
||||||
|
return
|
||||||
|
let div = this.message_list.querySelector('[data-uid="' + data.uid + '"]');
|
||||||
|
console.info(div)
|
||||||
|
if(!div){
|
||||||
|
let temp = document.createElement("chat-message");
|
||||||
|
temp.innerHTML = data.html
|
||||||
|
this.message_list.appendChild(temp)
|
||||||
|
//this.message_list.replace(div,temp)
|
||||||
|
//div.innerHTML = data.html
|
||||||
|
//this.message_list.appendChild(div);
|
||||||
|
}else{
|
||||||
|
// alert("HIERR")
|
||||||
|
let temp = document.createElement("chat-message");
|
||||||
|
temp.innerHTML = data.html;
|
||||||
|
div.innerHTML = temp.innerHTML
|
||||||
|
console.info("REPLACE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async connectedCallback() {
|
||||||
|
await this.rpc.ping(this.channel)
|
||||||
|
console.info(this.channelUid)
|
||||||
|
this.messages = await this.rpc.getMessages(this.channelUid, 0, 0);
|
||||||
|
this.messages.forEach((msg) => {
|
||||||
|
const temp = document.createElement("div");
|
||||||
|
temp.innerHTML = msg.html;
|
||||||
|
this.message_list.appendChild(temp.firstChild);
|
||||||
|
})
|
||||||
|
this.appendChild(this.component);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define("chat-window", ChatWindow);
|
||||||
|
</script>
|
||||||
|
<chat-window channel="df3e1259-7d1a-4184-b75c-3befd5bf08e1"></chat-window>
|
||||||
|
</body>
|
||||||
|
</html>
|
8
src/snek/view/new.py
Normal file
8
src/snek/view/new.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from snek.system.view import BaseView
|
||||||
|
|
||||||
|
|
||||||
|
class NewView(BaseView):
|
||||||
|
login_required = True
|
||||||
|
|
||||||
|
async def get(self):
|
||||||
|
return await self.render_template("new.html")
|
Loading…
Reference in New Issue
Block a user