Arcader7171 commited on
Commit
052d770
·
verified ·
1 Parent(s): c66d6cd

Update templates/app.html

Browse files
Files changed (1) hide show
  1. templates/app.html +51 -2
templates/app.html CHANGED
@@ -37,11 +37,60 @@
37
  return;
38
  }
39
 
40
- supabase
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  .channel("main/general")
42
  .on("broadcast", { event: 'new_message', schema: 'public', table: 'messages' }, payload => {
43
  console.log("New message received") // Temp for dev lol
44
- checkForMessage()
45
  })
46
  </script>
47
  </body>
 
37
  return;
38
  }
39
 
40
+ function sendMessage(msgContent) {
41
+ let heads = new Headers();
42
+ let creds = window.btoa({{ session["username"] }} + ":" + {{ session["password"] }})
43
+ heads.append("Authorization", `Basic ${creds}`);
44
+ heads.append("Content-Type", "application/json");
45
+ fetch("/api/messages", {
46
+ method: "POST",
47
+ headers: heads,
48
+ body: JSON.stringify({ content: msgContent })
49
+ })
50
+ .then(response => {
51
+ if (!response.ok) {
52
+ throw new Error("Response did not return ok")
53
+ }
54
+ response.json()
55
+ })
56
+ .then((data) => {
57
+
58
+ })
59
+ }
60
+
61
+ function addMsg2View(data) {
62
+ let author = data.author;
63
+ let content = data.content;
64
+ let local = data.local;
65
+ let id = data.id;
66
+ if (id > latest_msg_id) {
67
+ latest_msg_id = id;
68
+ }
69
+ let row = document.createElement("div");
70
+ let authorTxt = document.createElement("p");
71
+ let contentTxt = document.createElement("p");
72
+ let zone = document.getElementById("zone")
73
+
74
+ row.classList.add("MSG-Row");
75
+ authorTxt.classList.add("UserLabel");
76
+ contentTxt.classList.add("Message");
77
+ if (local == true) {
78
+ row.classList.add("R-Local");
79
+ authorTxt.classList.add("UL-Local");
80
+ contentTxt = document.add("M-Local");
81
+ }
82
+ authorTxt.textContent = author;
83
+ contentTxt.textContent = content;
84
+ row.appendChild(authorTxt);
85
+ row.appendChild(contentTxt);
86
+ zone.appendChild(row);
87
+ }
88
+
89
+ supabase // supabase will eventually be replaced for SSE and realtime! Check back soon
90
  .channel("main/general")
91
  .on("broadcast", { event: 'new_message', schema: 'public', table: 'messages' }, payload => {
92
  console.log("New message received") // Temp for dev lol
93
+ checkForMessage(payload)
94
  })
95
  </script>
96
  </body>