diff --git a/src/main/webapp/groupchat.html b/src/main/webapp/groupchat.html index 24e1803..fa867ad 100644 --- a/src/main/webapp/groupchat.html +++ b/src/main/webapp/groupchat.html @@ -10,5 +10,12 @@

Groupchat

+
+ +
+
+ + +
\ No newline at end of file diff --git a/src/main/webapp/script.js b/src/main/webapp/script.js index 47ca81f..79d95e2 100644 --- a/src/main/webapp/script.js +++ b/src/main/webapp/script.js @@ -38,3 +38,33 @@ function createCommentElement(comment) { function addParagraph(content) { return "

" + content + "

"; } + +function newGroupchat() { + const request = new Request("/load-groupchat", {method: 'POST'}); + fetch(request).then(response => response.text()).then((key) => { + redirectToGroupchat(key); + }); +} + +function loadGroupchat() { + const urlParams = new URLSearchParams(window.location.search); + const key = urlParams.get('key'); + fetch('/load-groupchat?key=' + key).then(response => response.json()) + .catch(error => { + alert('Error: Groupchat does not exist'); + window.location.href = 'index.html'; + }).then((messages) => { + const messageContainer = document.getElementById('messages'); + messageContainer.innerHTML = ''; + for (var i = 0; i < messages.length; i++) { + const message = document.createElement('p'); + message.innerText = messages[i]; + messageContainer.appendChild(message); + } + }); +} + +function redirectToGroupchat(keyParameter) { + const key = keyParameter ? keyParameter : document.getElementById('groupchat-key').value; + window.location.href = "/groupchat.html?key=" + key; +}